Edit report at http://bugs.php.net/bug.php?id=51808&edit=1

 ID:                 51808
 Comment by:         giorgio dot liscio at email dot it
 Reported by:        m dot przybylski at bkfmyjnie dot pl
 Summary:            Operator `new' does not support expressions for
                     class name
 Status:             Open
 Type:               Feature/Change Request
 Package:            Class/Object related
 Operating System:   linux/current
 PHP Version:        5.2.13
 Block user comment: N

 New Comment:

does not works too:



new MyClass()->method();

(new MyClass())->method();



new ($className = FuncGetClassAsString())();



these are not really important to fix, but are welcome, in future maybe


Previous Comments:
------------------------------------------------------------------------
[2010-08-03 17:58:55] + at ni-po dot com

Imho this isn't obvious at all. At least your proposed syntax `new
(func())()` isn't quite readable or understandable.

------------------------------------------------------------------------
[2010-05-13 12:53:31] m dot przybylski at bkfmyjnie dot pl

Description:
------------
Operator `new' accepts either class name as either symbol token or
variable

containing class name (T_STRING or

T_VARIABLE), but does not allow expressions returning class name.

Test script:
---------------
/* first form, works */

$handler = new SomeClass($constructorParam);



/* second form, works */

$handlerClass = handlerFor($something); /* returns name of some class to
be instantiated */

$handler = new $handlerClass($constructorParam);



/* third form -- does not work */

$handler = new (handlerFor($something))($constructorParam);

Expected result:
----------------
The third form ought to work just like the other two, so one doesn't
need to

create extra variable for single use.

Actual result:
--------------
PHP Parse error:  syntax error, unexpected '(', expecting T_STRING or
T_VARIABLE

or '$'


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51808&edit=1

Reply via email to