Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Nov 182010

Is PHP pass by reference or pass by value?


PHP is pass by value, see the code below:


class Dog {
	public $name;

	public function __construct($name) {
		$this->name = $name;


function bar($dog) {
	$dog = new Dog("bar");
	echo $dog->name;

$d = new Dog("foo");
echo $d->name;

echo $d->name;

If PHP is pass by reference, the last echo statement will print out "bar" instead of "foo", which is not true.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>