|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-08-03 17:58 UTC] + at ni-po dot com
[2010-08-03 22:47 UTC] giorgio dot liscio at email dot it
[2021-05-31 14:51 UTC] cmb@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: cmb
[2021-05-31 14:51 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 24 16:00:01 2025 UTC |
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 '$'