php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24089 Problem creating objects with names from class' fields
Submitted: 2003-06-09 04:09 UTC Modified: 2003-06-15 10:16 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bartosz at webcity dot pl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2003-06-09 (dev) OS: Linux
Private report: No CVE-ID: None
 [2003-06-09 04:09 UTC] 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'

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-09 04:18 UTC] derick@php.net
Where is the bug?
 [2003-06-09 04:28 UTC] 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 05:12 UTC] neon at neon-line dot net
It's not a bug.
 [2003-06-09 12:15 UTC] bartosz at webcity dot pl
So, why it works with php4, but with php5 doesn't?
 [2003-06-09 12:47 UTC] neon at neon-line dot net
Oh... I propably wasn't thinking while writing my previous comment.
For me it works with php5-200306091730 and PHP4. Are you sure that you don't have some kind of typing error etc. in you code...
 [2003-06-09 13:39 UTC] bartosz at webcity dot pl
Only notice about parse error, nothing else:

Parse error: parse error in /home/bartosz/www/foo.php on line 25
 [2003-06-09 22:56 UTC] sniper@php.net
Latest CVS gives:

Parse error: parse error in /home/jani/t.php on line 25

(for the script provided in the first comment in this report)

 [2003-06-15 07:23 UTC] stas@php.net
This is the same issue as bug #21669
 [2003-06-15 10:16 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Aug 16 17:01:28 2024 UTC