|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-09-07 22:01 UTC] 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';
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 09:00:01 2025 UTC |
>Yet, its perfectly able to override the class's variables > IF its not extended. What are you talking about? <?php class cText { var $desc = 'xxx'; function __construct( $fields = array() ) { extract($fields, EXTR_REFS); } } $user_name = new cText( array ( "_desc" => 'Name' ) ); var_dump($user_name->desc); ?> What do you get? "Name"? Or "xxx"?