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.

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/>";
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.