note 68152 modified in arrayobject.construct by danbrown

From: Date: Fri, 28 Nov 2008 21:40:08 +0000
Subject: note 68152 modified in arrayobject.construct by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147253@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 --was-- 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 http://php.net/manual/en/arrayobject.construct.php

« previous php.notes (#147253) next »