In PHP4, objects are passed by value and in PHP5 objects are passed by reference.
A sample program is shown below to get a better idea on this topic.
class myCar{
var $carModel;
function myCar($carModel){
$this->setModel($carModel);
}
function setModel($carModel){
$this->carModel = $carModel;
}
function getModel(){
return $this->carModel;
}
}
function changeMyCar($myNewCar, $carModel){
$myNewCar->setModel($carModel);
}
$myNewCar = new myCar(“Toyota”);
changeMyCar($myNewCar, “Ford”);
echo $myNewCar->getModel();
If you could execute this php file, you will get to know how the objects get passed across in PHP4 and how it differs in PHP5. Pass by value and pass by reference are still supported.