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.0.0 - 7.1.0
memory usage: 560 memory usage: 792 memory usage: 992 memory usage: 1192 memory usage: 1392 memory usage: 1592 memory usage: 1792 memory usage: 1992 memory usage: 2512
Output for hhvm-3.10.0 - 3.12.0
memory usage: 0 memory usage: 0 memory usage: 0 memory usage: 0 memory usage: 0 memory usage: 0 memory usage: 0 memory usage: 0 memory usage: 0
Output for 5.6.0 - 5.6.28
memory usage: 1280 memory usage: 1896 memory usage: 2472 memory usage: 3040 memory usage: 3608 memory usage: 4176 memory usage: 4744 memory usage: 5312 memory usage: 5944
Output for 5.4.0 - 5.5.38
memory usage: 1280 memory usage: 1880 memory usage: 2448 memory usage: 3016 memory usage: 3584 memory usage: 4152 memory usage: 4720 memory usage: 5288 memory usage: 5920
Output for 5.3.0 - 5.3.29
memory usage: 1576 memory usage: 2536 memory usage: 3464 memory usage: 4392 memory usage: 5320 memory usage: 6248 memory usage: 7176 memory usage: 8104 memory usage: 9096