Skip to content

Instantly share code, notes, and snippets.

@natmchugh
Created July 24, 2012 09:29
Show Gist options
  • Save natmchugh/3169075 to your computer and use it in GitHub Desktop.
Save natmchugh/3169075 to your computer and use it in GitHub Desktop.
call by reference example
<?php
class A {
function callByRef(&$var) {
$var->foo = 'bar';
$var = new stdclass;
$var->baz = 'bat';
}
function callOnObject($var) {
$var->foo = 'bar';
$var = new stdclass;
$var->baz = 'bat';
}
}
$a = new A;
$b = new stdclass;
$c = new stdclass;
$a->callByRef($b);
var_dump($b);
$a->callOnObject($c);
var_dump($c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment