|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2003-12-06 16:20 UTC] kmsluder at optonline dot net
[2003-12-06 16:53 UTC] derick@php.net
[2004-01-10 10:41 UTC] andrey@php.net
[2009-02-27 08:07 UTC] james dot relyea at zifiniti dot com
[2014-03-05 20:22 UTC] narf at devilix dot net
[2014-08-19 16:11 UTC] levim@php.net
-Status: Open
+Status: Duplicate
-Package: Feature/Change Request
+Package: *General Issues
[2014-08-19 16:11 UTC] levim@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 05:00:01 2025 UTC |
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 } } }