Last active
January 30, 2016 14:31
-
-
Save dana-ross/aba8cd3ffa7e309ee365 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Return the object's value + 2 | |
*/ | |
function f( $obj ) { | |
$retval = $obj->value + 2; | |
$obj->value = 5; // EVIL! | |
return $retval; | |
} | |
/** | |
* Return the object's value + 3 | |
*/ | |
function g( $obj ) { | |
return $obj->value + 3; | |
} | |
$myObj = new stdClass(); | |
$myObj->value = 1; | |
echo f( $myObj ) + g( $myObj ); // Outputs 11, not 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment