View Single Post
  #6 (permalink)  
Old 12-07-2005, 12:17 PM
kgun's Avatar
kgun kgun is offline
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,714
kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10
Default Is PHP a true OOP language?

The answer to this is no, but it becomes more and more a true OOP language. What is the main difference from a true OOP language as C++?

1. Privacy.
PHP 5.0 is more OO than PHP 4.0 since it opens for privacy of class members.

2. Inheritance.
As far as I know PHP has no multiple inheritance possibility.

3. Pointers and references
If you are used to C++ or Java, a reference in PHP is not the same as a reference in C++ or Java. In those languages, a reference is a pointer to a memory location. So passing a variable by value or by reference is different in PHP. If you intend to link to the original variable, you must pass values by reference. If you pass by value (copy) and the original variable changes, your (copied) variable is not the same as the source variable.

Good Example from the PHP book above in chapter 2. & is the reference operator.

<?php
$color = 'blue';
$settings['color'] = $color; // Makes a copy
$color = 'red'; //color changes
echo $settings['color']; // Displays "blue"
?>

Then note:

<?php
$color = 'blue';
$settings['color'] = &$color; // Makes a reference
$color = 'red'; //color changes
echo $settings['color']; // Displays "red"
?>

So passing by reference allows you to keep the new variable "linked" to the original source variable.

Remember: And C++ like Java is a compiled language, while PHP is interpreted. That means that the same operation is much slower in PHP.
Reply With Quote