ID: 41163 Updated by: [EMAIL PROTECTED] Reported By: info at deltateam-design dot de -Status: Open +Status: Bogus Bug Type: Unknown/Other Function Operating System: Windows XP SP2 PHP Version: 5.2.1 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 $error_type[$error_code] is evaluated first to get the Property name. You want $this->{$error_type}[$error_code] or something similar. Previous Comments: ------------------------------------------------------------------------ [2007-04-22 14:43:17] info at deltateam-design dot de 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 this bug report at http://bugs.php.net/?id=41163&edit=1
