#42441 [Bgs]: Unable to instanciate a class who's name is in a constant
| From: | romain dot tartiere at healthgrid dot org | Date: | Thu, 30 Aug 2007 08:58:53 +0000 |
| Subject: | #42441 [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-116865@lists.php.net to get a copy of this message | ||
ID: 42441
User updated by: romain dot tartiere at healthgrid dot org
Reported By: romain dot tartiere at healthgrid dot org
Status: Bogus
Bug Type: Feature/Change Request
Operating System: GNU/Linux
PHP Version: 5.2.3
New Comment:
Not meant to work? haha! BTW, you may reconsider the status of bug
#23022 since it is exactly the same kind of problem (parser can only
cope with simple situations).
Previous Comments:
------------------------------------------------------------------------
[2007-08-30 07:12:49] derick@php.net
A quick close doesn't mean it wasn't a correct close. This is not a
bug, it's not meant to work. And don't lecture us about LALR parsers
when you have no idea how PHP works.
------------------------------------------------------------------------
[2007-08-27 12:42:34] romain dot tartiere at healthgrid dot org
Thank you for your personalised answer and taking time to read and
understand my bug report.
There is nothing about this behaviour in:
-
http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.new
- http://php.net/manual/en/language.constants.php
Moreover, the behaviour I describe is common to all programming
languages I know (I don't pretent to know all languages, I just tell
that PHP constants are not like other programming language constants).
According to me, it is just a LALR parser mistake.
Something like...
stuff: [...]
| TOK_NEW string '(' ')'
| TOK_NEW variable '(' ')'
... instead of ...
stuff: [...]
| TOK_NEW expression '(' ')'
Sorry for being rude, but your copy-paste-reply make me feel my problem
has been underestimated by an inexperienced person. But maybe I am
wrong, then just prove me that what I am talking about is nonsense...
According to me, if I can't do "new a" but can do "b = a; new b", there
is something wrong.
------------------------------------------------------------------------
[2007-08-27 10:22:24] jani@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
------------------------------------------------------------------------
[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