3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class IAmImmutable { private $name; public static function createFromName($name) { return new self($name); } private function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } } $object = new IAmImmutable('Peter'); var_dump($object->getName()); $object->__construct('Bob'); var_dump($object->getName());
based on QcuWC
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to private IAmImmutable::__construct() from invalid context in /in/jQN5u:23 Stack trace: #0 {main} thrown in /in/jQN5u on line 23
Process exited with code 255.
Output for 5.3.19 - 5.6.28
Fatal error: Call to private IAmImmutable::__construct() from invalid context in /in/jQN5u on line 23
Process exited with code 255.