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 function setProperty($property) { $this->property=$property;} public function 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 7.1.0
Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400 Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400 Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400 Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400 Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400 Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400 Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400 Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400 Warning: A non-numeric value encountered in /in/FPL1s on line 47 -359400
Output for 7.0.0 - 7.0.14
-359384 -359384 -359384 -359384 -359384 -359384 -359384 -359384 -359384
Output for hhvm-3.10.0 - 3.12.0
-2097152 -2097152 -2097152 -2097152 -2097152 -2097152 -2097152 -2097152 -2097152
Output for 5.6.0 - 5.6.28
-247624 -247624 -247624 -247624 -247624 -247624 -247624 -247624 -247624
Output for 5.5.0 - 5.5.38
-247528 -247528 -247528 -247528 -247528 -247528 -247528 -247528 -247528
Output for 5.4.0 - 5.4.45
-247792 -247792 -247792 -247792 -247792 -247792 -247792 -247792 -247792
Output for 5.3.11 - 5.3.29
-659712 -659712 -659712 -659712 -659712 -659712 -659712 -659712 -659712
Output for 5.3.0 - 5.3.10
-659408 -659408 -659408 -659408 -659408 -659408 -659408 -659408 -659408