Created
April 17, 2011 19:26
-
-
Save loganlinn/924388 to your computer and use it in GitHub Desktop.
PHP __callStatic by Reference
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 | |
error_reporting(E_ALL); | |
ini_set('display_errors', true); | |
class Test { | |
private static $_inst = array(); | |
public static function & __callStatic ($name, $args) { | |
if (!isset(self::$_inst[$name])){ | |
echo "Created \n"; | |
self::$_inst[$name] = (object) "test"; | |
} | |
return self::$_inst[$name]; | |
} | |
} | |
$a =& Test::abc(); | |
var_dump($a); // prints 'Created' | |
$a = null; | |
var_dump(Test::abc()); // doesn't print 'Created' and the instance still exists in Test::$_inst | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment