|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 23:00:01 2025 UTC |
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