Skip to content

Instantly share code, notes, and snippets.

@fredemmott
Created August 26, 2015 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredemmott/bc018d889c4700f10c03 to your computer and use it in GitHub Desktop.
Save fredemmott/bc018d889c4700f10c03 to your computer and use it in GitHub Desktop.
<?hh
class MyClass {
public function __construct() {
var_dump(__FUNCTION__);
}
public function foo() {
var_dump(spl_object_hash($this));
}
}
function main() {
$proxy = () ==> {static $it = null; $it = $it ?: new MyClass(); return $it;};
var_dump('made proxy');
$proxy()->foo();
$proxy()->foo();
}
main();
@fredemmott
Copy link
Author

string(10) "made proxy"
string(11) "__construct"
string(32) "0000000000000000af7d8023c4ffef5b"
string(32) "0000000000000000af7d8023c4ffef5b"

Identical hash shows it's the same object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment