Skip to content

Instantly share code, notes, and snippets.

@dana-ross
Last active January 30, 2016 14:31
Show Gist options
  • Save dana-ross/aba8cd3ffa7e309ee365 to your computer and use it in GitHub Desktop.
Save dana-ross/aba8cd3ffa7e309ee365 to your computer and use it in GitHub Desktop.
<?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