3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class A{ static protected $shared = array(); static function create(){ if (isset(static::$shared['mailer'])){ return static::$shared['mailer']; } $mailer = new static(); //this is the correct way return static::$shared['mailer'] = $mailer; } } class B extends A{ } $obj=B::create(); var_dump($obj);

preferences:
38.58 ms | 402 KiB | 5 Q