ID:               26545
 User updated by:  kmsluder at optonline dot net
 Reported By:      kmsluder at optonline dot net
 Status:           Open
 Bug Type:         Class/Object related
 Operating System: Linux 2.4.2
 PHP Version:      4.3.4
 New Comment:

Note to anyone that says that the extra two lines aren't a big deal:
it's a lot more than two if you need to emulate some of the more
sophisticated (and rather useful) features of extract().


Previous Comments:
------------------------------------------------------------------------

[2003-12-06 16:11:31] kmsluder at optonline dot net

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 this bug report at http://bugs.php.net/?id=26545&edit=1

Reply via email to