php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31069 Can't call variable objects.
Submitted: 2004-12-13 15:18 UTC Modified: 2004-12-13 16:31 UTC
From: jody_leigh_salt at yahoo dot co dot uk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.2 OS: XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jody_leigh_salt at yahoo dot co dot uk
New email:
PHP Version: OS:

 

 [2004-12-13 15:18 UTC] jody_leigh_salt at yahoo dot co dot uk
Description:
------------
Can't call variable objects. Where as in PHP 4 you can!!

Reproduce code:
---------------
class bug_test {
function bug_test() {
//create a test var
$this->test_var = 'hello world';
}
function echo_test_var() {
echo $this->test_var;
}
function say_hello() {
$object = 'this';
$$object->echo_test_var();
}
}

//let show this bug!!
$test = new bug_test();
$test->say_hello();

Expected result:
----------------
Should print "hello world to screen"

Actual result:
--------------
Notice: Undefined variable: this in c:\www\php_newrust\bug.php on line 20

Fatal error: Call to a member function echo_test_var() on a non-object in c:\www\php_newrust\bug.php on line 20

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-13 15:32 UTC] jody_leigh_salt at yahoo dot co dot uk
Edited submission as I feel as it can be better catagorised
 [2004-12-13 15:49 UTC] derick@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. 

Thank you for your interest in PHP.

See #31068
 [2004-12-13 15:54 UTC] jody_leigh_salt at yahoo dot co dot uk
I have found an interesting hack to make it work, which means the problem is the fact that the "$this" self reference object is not been seen as a variable.

class bug_test {
function echo_test_var() {
echo "hello world";
}
function say_hello() {
$this_ref =& $this;
$hack = 'this_ref';
$$hack->echo_test_var();
}
}

//let show this bug!!
$test = new bug_test();
$test->say_hello();

Hope it helps

Cheers

Jody
 [2004-12-13 16:34 UTC] derick@php.net
It's still not a bug. This is not supposed to work.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 06:01:33 2024 UTC