#24089 [Com]: Problem creating objects with names from class' fields
| From: | neon at neon-line dot net | Date: | Mon, 09 Jun 2003 10:12:34 +0000 |
| Subject: | #24089 [Com]: Problem creating objects with names from class' fields | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-41504@lists.php.net to get a copy of this message | ||
ID: 24089
Comment by: neon at neon-line dot net
Reported By: bartosz at webcity dot pl
Status: Open
Bug Type: *General Issues
Operating System: Linux
PHP Version: 5CVS-2003-06-09 (dev)
New Comment:
It's not a bug.
Previous Comments:
------------------------------------------------------------------------
[2003-06-09 04:28:43] bartosz at webcity dot pl
Look at 'foobar' method in 'foobar' class.
It makes parse error:
$this -> obj = new $this -> classname;
but it works:
$classname = $this -> classname;
$this -> obj = new $classname;
in php4
$this -> obj = new $this -> classname;
works correctly.
It isn't a bug?
------------------------------------------------------------------------
[2003-06-09 04:18:28] derick@php.net
Where is the bug?
------------------------------------------------------------------------
[2003-06-09 04:09:37] bartosz at webcity dot pl
Analyse code below, it makes parse error:
<?php
class foobar2
{
function foobar2()
{
echo phpversion();
}
}
class foobar
{
var $classname = 'foobar2';
var $obj;
function foobar()
{
// it works:
//
// $classname = $this -> classname;
// $this -> obj = new $classname;
//
// but it doesn't work:
$this -> obj = new $this -> classname;
}
}
$obj = new foobar;
?>
----------------------------------------
My configure command:
'./configure' '--with-mysql=/usr' '--with-gd2'
'--disable-xml'
'--with-apxs=/usr/sbin/apxs'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24089&edit=1