Created
July 24, 2012 09:29
-
-
Save natmchugh/3169075 to your computer and use it in GitHub Desktop.
call by reference example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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