In a previous post, I mentioned that arrays in PHP are passed by value.ce,

For some reason, there are mixed information about if PHP objects are passed by reference, so I decided to write a short block of code to find out. The result is, as PHP 5, object are passed by reference.

The following is a short PHP file for the purpose of testing.

<?php
class Test
{
    public $a = 'abc';
    public $b = 'cde';
}

function change($test)
{
    $test->a = 'aaa';
    $test->b = 'bbb';
}

$test = new Test;
echo "Before: a = $test->a, b = $test->b <br/>";
change($test);
echo "After: a = $test->a, b = $test->b";
?>

The output of this PHP file from the web server follows:

Before: a = abc, b = cde
After: a = aaa, b = bbb

This shows, PHP passes objects by reference.

Reference: http://stackoverflow.com/questions/2715026/are-php5-objects-passed-by-reference