Bug #74633 [Nab]: object as class name

From: Date: Mon, 22 May 2017 22:31:23 +0000
Subject: Bug #74633 [Nab]: object as class name
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14719@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 User updated by: d dot albano at gmail dot com 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: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#14719) next »