3v4l.org

run code in 300+ PHP versions simultaneously
<?php class X { } class XFactory { private $className = 'X'; private function getClassName() { return $this->className; } public function create() { return array( 'member without parens' => new $this->className, 'member with parens' => new $this->className(), // 'method without parens' => new $this->getClassName, # Does not work at all 'method with parens' => new $this->getClassName(), 'method with double parens' => new ($this->getClassName())(), 'method with encapsed parens' => new ($this->getClassName())(), ); } } $factory = new XFactory(); var_dump($factory->create());

preferences:
27.58 ms | 402 KiB | 5 Q