#41163 [NEW]: Cannot access class-intern array using $this-> in combination with a variable

From: Date: Sun, 22 Apr 2007 14:43:17 +0000
Subject: #41163 [NEW]: Cannot access class-intern array using $this-> in combination with a variable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111777@lists.php.net to get a copy of this message
From: info at deltateam-design dot de Operating system: Windows XP SP2 PHP version: 5.2.1 PHP Bug Type: Unknown/Other Function Bug description: Cannot access class-intern array using $this-> in combination with a variable Description: ------------ I tried to access a private variable (an array) using $this->$error_type[$error_code], but PHP failed and gave me a notice about a non-existent offset. Using var_dump/print_r on $this->$error_type returned the desired array with all elements. I've double-checked everything and the only way I found to solve this was creating a local copy of the array. Notice on the code: - $this->db_error is an array with an offset called (INVALID_CONNECTION_STRING) - The code was called via function __get() Reproduce code: --------------- <?php $error_code = 'DB_INVALID_CONNECTION_STRING'; $temp_array = explode('_', $error_code, 2); $error_type = (string) strtolower($temp_array[0]) . '_error'; // Value: db_error $error_code = (string) $temp_array[1]; // Value: INVALID_CONNECTION_STRING // *** // *** This does not work // *** echo $this->$error_type[$error_code]; // *** // *** This does work (local copy of the array) // *** $error_array = $this->$error_type; echo $error_array[$error_code]; ?> Expected result: ---------------- Return an error-message from an array identified by its error-code Actual result: -------------- With the local copy it prints the correct value associated with the identifier $error_code Without a local copy: Notice: Undefined offset: 1 in C:\Path\To\Files\Errors.php on line 86 Notice: Undefined property: ErrorMessage::$d_error in C:\Path\To\Files\Errors.php on line 87 Notice: Undefined property: ErrorMessage::$d in C:\Path\To\Files\Errors.php on line 89 Notice: Undefined property: ErrorMessage::$d in C:\Path\To\Files\Errors.php on line 89 -- Edit bug report at http://bugs.php.net/?id=41163&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41163&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41163&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41163&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41163&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41163&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41163&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41163&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41163&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41163&r=support Expected behavior: http://bugs.php.net/fix.php?id=41163&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41163&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41163&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41163&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41163&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41163&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41163&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41163&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41163&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41163&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41163&r=mysqlcfg

« previous php.bugs (#111777) next »