note 68152 added to function.arrayobject-construct

From: Date: Sat, 15 Jul 2006 10:51:43 +0000
Subject: note 68152 added to function.arrayobject-construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-114802@lists.php.net to get a copy of this message
As Marcus explained, the flag ArrayObject::SPL_ARRAY_AS_PROPS means the array element may be used as a property if there is no conflict with visible properties. If there are visible properties in the class, the array element will not overwrite it's value. <?php class Rules extends ArrayObject { public $len = 1; function __construct($array){ parent::__construct($array,ArrayObject::ARRAY_AS_PROPS); $this['len'] = 2; } } $x = new Rules(array(1,2)); echo $x->len; ?> Result: 1 <?php class Rules extends ArrayObject { private $len = 1; function __construct($array){ parent::__construct($array,ArrayObject::ARRAY_AS_PROPS); $this['len'] = 2; } } $x = new Rules(array(1,2)); echo $x->len; ?> Result: 2 ---- Server IP: 66.163.161.117 Probable Submitter: 82.207.103.174 (proxied: 10.1.1.2) ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.arrayobject-construct.php Edit -- http://master.php.net/note/edit/68152 Del: integrated -- http://master.php.net/note/delete/68152/integrated Del: useless -- http://master.php.net/note/delete/68152/useless Del: bad code -- http://master.php.net/note/delete/68152/bad+code Del: spam -- http://master.php.net/note/delete/68152/spam Del: non-english -- http://master.php.net/note/delete/68152/non-english Del: in docs -- http://master.php.net/note/delete/68152/in+docs Del: other reasons-- http://master.php.net/note/delete/68152 Reject -- http://master.php.net/note/reject/68152 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114802) next »