ID:               38745
 User updated by:  arqentus at arqentus dot com
 Reported By:      arqentus at arqentus dot com
-Status:           Bogus
+Status:           Open
 Bug Type:         Class/Object related
 Operating System: Windows 2003
 PHP Version:      5.1.6
 New Comment:

"extract() creates variables in the current scope, it doesn't create
objects' attributes and was never meant to do it."

Yet, its perfectly able to override the class's variables IF its not
extended. In other words, while as you say, its not designed to work
for classes, it does actually work ( if used only in a baseclass ).

So, you are right, its not a complete bug, its a incomplete "feature"
thats lacking the ability to see past its current scope with a extended
class.

Note: See several examples on the general mailing list where people use
the same methode.

The extract function will need a update to it scope range. Using a
foreach loop is a rather inefficient way of handeling it compared to a
extract.


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

[2006-09-07 22:09:28] [EMAIL PROTECTED]

Actually it has nothing to do with EXTR_.
extract() creates variables in the current scope, it doesn't create
objects' attributes and was never meant to do it.

------------------------------------------------------------------------

[2006-09-07 22:05:26] arqentus at arqentus dot com

Note: The extract code was texted with EXTR_OVERWRITE & EXTR_IF_EXISTS.
The "EXTR_REFS" was a final foolish attempt to see how it was going to
react( expecting a error feedback, but nothing came ). Forgot to remove
it from the submitted code.

I'm including this comment, to be sure this bug does not get closed
becouse you think i used the wrong EXTR ;)

------------------------------------------------------------------------

[2006-09-07 22:01:51] arqentus at arqentus dot com

Description:
------------
extract does not override the values when using a extended class.

Note: Using a manual fill, will work:

class cText extends cField{ 

        function __construct( $fields = array() ) {
                foreach($fields as $key => $val ) {
                        $this->{$key} = $val;
                }
                //extract($fields, EXTR_REFS);
        }
}

Looks like the extract can't handle the extend class.
Note: Using a normal NONE extended class, and extract will work.
Somehow it seems to lack the scope. Yet, a 'manual' foreach loop is
able to access the scope.

Differend combination have been tried ( moving the construct to the
parent, passing the fields to the parent and extracting there, etc ).
None are able to work.

Reproduce code:
---------------
class cField{

        var $desc = 'xxx';
        
}

class cText extends cField{ 

        function __construct( $fields = array() ) {
                extract($fields, EXTR_REFS);
        }

}

$user_name = new cText( array ( _desc => 'Name' ) );
echo $user_name->desc;

Expected result:
----------------
The expect result is: 'Name';



Actual result:
--------------
The result archieved is: 'xxx';


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=38745&edit=1

Reply via email to