Req #51808 [Com]: Operator `new' does not support expressions for class name

From: Date: Tue, 03 Aug 2010 15:58:55 +0000
Subject: Req #51808 [Com]: Operator `new' does not support expressions for class name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-153062@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51808&edit=1

 ID:                 51808
 Comment by:         + at ni-po dot com
 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:

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


Previous Comments:
------------------------------------------------------------------------
[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


Thread (4 messages)

« previous php.bugs (#153062) next »