3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php abstract class Catalog_Model_DbSelect_Abstract { /** All created instances so far */ protected static $_instances = array(); protected $property; /** * Gets the singleton of a select statement * @param array|string $args The arguments arguments that are needed to build the select (e.g. attribute set names, product types). * @return Catalog_Model_DbSelect_Abstract The select instance */ public static function getInstance($args = null) { $class = get_called_class(); $key = $class . (is_array($args) ? implode('_', $args) : $args); if (!array_key_exists($key, static::$_instances)) { static::$_instances[$key] = new $class($args); } return clone static::$_instances[$key]; } public setProperty($property) { $this->property=$property;} public getProperty() { return $this->property;} } class DerivedClass1 extends Catalog_Model_DbSelect_Abstract {} class DerivedClass2 extends Catalog_Model_DbSelect_Abstract {} class DerivedClass3 extends Catalog_Model_DbSelect_Abstract {} class DerivedClass4 extends Catalog_Model_DbSelect_Abstract {} class DerivedClass5 extends Catalog_Model_DbSelect_Abstract {} class DerivedClass6 extends Catalog_Model_DbSelect_Abstract {} class DerivedClass7 extends Catalog_Model_DbSelect_Abstract {} class DerivedClass8 extends Catalog_Model_DbSelect_Abstract {} class DerivedClass9 extends Catalog_Model_DbSelect_Abstract {} $mem = memory_get_usage(); for ($i=1;$i<10;$i++) { $varname = 'instance' . $i; $classname = 'DerivedClass' . $i; $$varname = $classname::getInstance('foo'); echo 'memory usage: ' . memory_get_usage() - $mem . PHP_EOL; }
Output for 5.4.0 - 5.4.14
Parse error: syntax error, unexpected 'setProperty' (T_STRING), expecting variable (T_VARIABLE) in /in/dkYMa on line 24
Process exited with code 255.
Output for 5.3.0 - 5.3.24
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /in/dkYMa on line 24
Process exited with code 255.