#33652 [NEW]: $this not available in a variable variable

From: Date: Tue, 12 Jul 2005 01:06:44 +0000
Subject: #33652 [NEW]: $this not available in a variable variable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-81702@lists.php.net to get a copy of this message
From: ludvig dot ericson at gmail dot com Operating system: Windows XP PHP version: 5.0.4 PHP Bug Type: Variables related Bug description: $this not available in a variable variable 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 bug report at http://bugs.php.net/?id=33652&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33652&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33652&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33652&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33652&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33652&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33652&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33652&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33652&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33652&r=support Expected behavior: http://bugs.php.net/fix.php?id=33652&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33652&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33652&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33652&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33652&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33652&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33652&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33652&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33652&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33652&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33652&r=mysqlcfg

« previous php.bugs (#81702) next »