#33652 [Asn->Bgs]: $this not available in a variable variable
| From: | derick@php.net | Date: | Tue, 12 Jul 2005 09:32:32 +0000 |
| Subject: | #33652 [Asn->Bgs]: $this not available in a variable variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-81717@lists.php.net to get a copy of this message | ||
ID: 33652
Updated by: derick@php.net
Reported By: ludvig dot ericson at gmail dot com
-Status: Assigned
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: *
PHP Version: 5CVS-2005-07-11
Assigned To: dmitry
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Previous Comments:
------------------------------------------------------------------------
[2005-07-12 10:20:41] sniper@php.net
Works fine with PHP 4.4.0, not with latest CVS HEAD.
------------------------------------------------------------------------
[2005-07-12 03:30:20] colder@php.net
Notice also that ${'this'} will work but not ${'this'.''} or
${(string)'this'} for example.
It should be at least documented that this pseudo-variable lacks some
features.
------------------------------------------------------------------------
[2005-07-12 03:06:43] ludvig dot ericson at gmail dot com
Description:
------------
Using variable variables ($$MyVar) in classes, through functions that
is, doesn't allow $this to be used.
I tried with $this (notice the $) too, no difference.
A workaround is to check the object name, if it's "this" you could
$this->$Mem instead.
Reproduce code:
---------------
<?php
class Foo {
public $MyVal = "Test";
public Bar($Obj, $Mem) {
return ${$Obj}->$Mem;
}
}
$TheObject = new Foo();
$Objname = "this";
$Memname = "MyVal";
echo $TheObject->Bar($Objname, $Memname);
?>
Expected result:
----------------
I expect it to output "Test"
Actual result:
--------------
Notice: Undefined variable: this in (filepath) on line 6
Notice: Trying to get property of non-object in (filepath) on line 6
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33652&edit=1