3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php Class ObjectPool { private $objectPool = array(); private $object; public function __construct($object) { $this->object = $object; } public function release() { $this->objectPool[] = $this->object; } public function get() { if (count($this->objectPool) > 0) { return array_pop($objectPool); } return new $this->object; } } Class Test { public $id = 1; } $pool = new ObjectPool('Test'); $testWorker = $pool->get(); $testWorker2 = $pool->get(); var_dump($testWorker); var_dump($testWorker2);
based on SQEki
Output for 5.5.0 - 7.3.0rc3
object(Test)#2 (1) { ["id"]=> int(1) } object(Test)#3 (1) { ["id"]=> int(1) }