Skip to content

Instantly share code, notes, and snippets.

@loganlinn
Created April 17, 2011 19:26
Show Gist options
  • Save loganlinn/924388 to your computer and use it in GitHub Desktop.
Save loganlinn/924388 to your computer and use it in GitHub Desktop.
PHP __callStatic by Reference
<?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