ID:               42441
 User updated by:  romain dot tartiere at healthgrid dot org
 Reported By:      romain dot tartiere at healthgrid dot org
-Status:           Bogus
+Status:           Open
 Bug Type:         Class/Object related
 Operating System: GNU/Linux
 PHP Version:      5.2.3
 New Comment:

Reopen bug since it seems to have been closed too quickly.


Previous Comments:
------------------------------------------------------------------------

[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] [EMAIL PROTECTED]

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

Reply via email to