Bug #74633 [Nab]: object as class name

From: Date: Tue, 23 May 2017 06:58:13 +0000
Subject: Bug #74633 [Nab]: object as class name
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14720@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74633&edit=1 ID: 74633 Updated by: requinix@php.net Reported by: d dot albano at gmail dot com Summary: object as class name Status: Not a bug Type: Bug Package: Documentation problem Operating System: Mac OS X 10.12.5 PHP Version: 7.1.5 Block user comment: N Private report: N New Comment: Did you read example #5? PHP 5.3.0 introduced a couple of new ways to create instances of an object: $obj1 = new Test(); $obj2 = new $obj1; var_dump($obj1 !== $obj2); Previous Comments: ------------------------------------------------------------------------ [2017-05-22 22:31:18] d dot albano at gmail dot com The documentation states that it is possible to pass to new a variable containing the name of the class to instantiate (a string in the example) but the code I am passing an object. Trying to echo the object results in an error and defining the to string magic method doesn't affect the behavior of the new keyword. ------------------------------------------------------------------------ [2017-05-22 17:40:13] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.new ------------------------------------------------------------------------ [2017-05-22 17:36:13] d dot albano at gmail dot com Description: ------------ It is possible to use an object as class name in new Test script: --------------- <?php class Foo { }; $foo = new Foo(); $bar = new $foo(); var_dump([$foo, $bar]); Expected result: ---------------- Error, cannot use $foo as class name Actual result: -------------- array(2) { [0]=> object(Foo)#1 (0) { } [1]=> object(Foo)#2 (0) { } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74633&edit=1

« previous php.doc.bugs (#14720) next »