#42441 [Opn->Bgs]: Unable to instanciate a class who's name is in a constant

From: Date: Mon, 27 Aug 2007 10:22:24 +0000
Subject: #42441 [Opn->Bgs]: Unable to instanciate a class who's name is in a constant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116710@lists.php.net to get a copy of this message
ID: 42441 Updated by: jani@php.net Reported By: romain dot tartiere at healthgrid dot org -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: GNU/Linux PHP Version: 5.2.3 New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2007-08-27 10:08:45] romain dot tartiere at healthgrid dot org Description: ------------ If you use define to set the name of a class to a constant, you can't use it to instanciate the class. Reproduce code: --------------- <?php class foo {} define('MYCLASS', 'foo'); $f = new MYCLASS(); # Won't work $f = new $_CONSTANTS['MYCLASS'](); # Won't work $s = MYCLASS; $f = new $s(); # Works ?> Expected result: ---------------- These way of instanciating the foo class should all work. Actual result: -------------- The two first syntax produce the same result: Fatal error: Class name must be a valid object or a string ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42441&edit=1

« previous php.bugs (#116710) next »