ID: 38745
Updated by: [EMAIL PROTECTED]
Reported By: arqentus at arqentus dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Windows 2003
PHP Version: 5.1.6
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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