#21669 [Opn->Ver]: "$obj = new $this->var;" doesn't work
| From: | sander@php.net | Date: | Sun, 02 Mar 2003 11:15:29 +0000 |
| Subject: | #21669 [Opn->Ver]: "$obj = new $this->var;" doesn't work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-34615@lists.php.net to get a copy of this message | ||
ID: 21669
Updated by: sander@php.net
Reported By: slowbyte at hot dot ee
-Status: Open
+Status: Verified
Bug Type: Zend Engine 2 problem
Operating System: Debian Linux 3.0r0
PHP Version: 5CVS-2003-01-15 (dev)
New Comment:
Verified with latest CVS.
Previous Comments:
------------------------------------------------------------------------
[2003-02-18 12:51:16] yoglets at hotmail dot com
FWIW, this problem is still present in a post-nested-class ZE2 build:
<?php
namespace Foo
{
class Bar
{
}
}
$name = 'Foo::Bar';
$obj = new $name;
print_r($obj);
?>
------------------------------------------------------------------------
[2003-01-28 19:55:58] yoglets at hotmail dot com
Don't know if this is the same issue or not, but it's certainly
related. You can't use $obj = new $name for nested classes either. For
example:
<?php
class Foo {
class Bar {
}
}
$obj1 = new Foo; // works
$obj2 = new Foo::Bar; // works
$name = 'Foo';
$obj3 = new $name; // works
$name = 'Foo::Bar';
$obj4 = new $name; // Fatal error: Class 'foo::bar' not found
?>
------------------------------------------------------------------------
[2003-01-15 11:56:13] slowbyte at hot dot ee
The following snippet is a parse error in PHP5-ZE2 (used to work on
earlier versions). This feature is also used in Smarty templates.
<?php
class Test {
function say_hello() {
echo "Hello world";
}
}
class Factory {
var $name = "Test";
function create() {
$obj = new $this->name; /* Parse error */
return $obj;
}
}
$factory = new Factory;
$test = $factory->create();
$test->say_hello();
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=21669&edit=1