#23643 [Bgs]: Parse error when instancing object from a class property

From: Date: Sat, 17 May 2003 20:11:19 +0000
Subject: #23643 [Bgs]: Parse error when instancing object from a class property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-39852@lists.php.net to get a copy of this message
ID: 23643 Updated by: et@php.net Reported By: php at schlueters dot de Status: Bogus Bug Type: Zend Engine 2 problem Operating System: Linux 2.4.20 PHP Version: 5CVS-2003-05-15 (dev) New Comment: When using ZE2, this will indeed result in a parse error. When using ZE1, it works and the property name will be used as the class name to be instanciated. et@edea:~$ /usr/local/sources/php-4.3.1/sapi/cli/php <?php class Foo { var $bar = 'Foo'; } $foo1 = new Foo; $foo2 = new $foo1->bar; ?> et@edea:~$ /usr/local/sources/unstable/php5-200305031330/sapi/cli/php <?php class Foo { var $bar = 'Foo'; } $foo1 = new Foo; $foo2 = new $foo1->bar; Parse error: parse error in - on line 6 But i think this is the way it should be, because it looks ambiguous when you see new $object1->name($arg); - on the first look, it looks like a call to the method `name' and not like passing arguments to a constructor. Somehow, it's the same for the new $name() - it could be mistaken as a dynamic function call. Maybe there should be a function to instantiate objects dynamically? Like object create_instance(string classname[, mixed constructor_args...]) Previous Comments: ------------------------------------------------------------------------ [2003-05-15 12:20:58] helly@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 $name will be used as the class name to be instanciated. ------------------------------------------------------------------------ [2003-05-15 10:04:57] php at schlueters dot de I'm running this script using different php5 snapshots and current php5-CVS-Versions: <?php class myclass { var $name = 'myclass'; } $object1 = new myclass(); $object2 = new $object1->name(); // Parse error ?> Gives a parse error at the marked line but <?php $name = $object1->name; $object2 = new $name(); ?> works. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23643&edit=1

« previous php.bugs (#39852) next »