From: kmsluder at optonline dot net Operating system: Linux 2.4.2 PHP version: 4.3.4 PHP Bug Type: Class/Object related Bug description: Cannot extract() variables into class scope
Description: ------------ extract() cannot be used inside an object member function to set object var's. Using extract normally brings the variables into the scope of the function (as expected), but there is no way to bring array key/value pairs to object scope without a foreach statement. It would be nice to specify what scope the variables should be created in, or even create a different function specifically to set the member variables of an object. Reproduce code: --------------- class MyClass { var $m1; // Imagine a class with fifty variables, var $m2; // Not all of which must be set. var $m3; // This is why you would want to use extract(). function Init($info) { extract($info, EXTR_OVERWRITE); // Doesn't work; extracted to function scope extract($info, EXTR_PREFIX_ALL, "$this->"); // Stupid idea; not a valid variable name foreach($info as $key => $value) { $this->$key = $value; // Works, but ugly } } } -- Edit bug report at http://bugs.php.net/?id=26545&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26545&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26545&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26545&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26545&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26545&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=26545&r=needscript Try newer version: http://bugs.php.net/fix.php?id=26545&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26545&r=support Expected behavior: http://bugs.php.net/fix.php?id=26545&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26545&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26545&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26545&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26545&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26545&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26545&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26545&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26545&r=float