arrays - PHP object dynamic properties -
i can't create dynamic property inside class or can't see them.
class sess { public $session = []; public function __construct() { $_session = [ 'one' => [[1], ['jeden'], ['eins'], ['uno']], 'two' => [2, 'dwa', 'zwei', 'dos'], 'three' => [3, 'trzy', 'drei', 'tres'] ]; $this->session = $_session; var_dump($this->session); foreach ($this->session $property => $value) { $this->{$property} = $value; } unset($this->session); var_dump(get_object_vars($this)); var_dump($this->one); die('end'); }} but output doesn't show new properties.
array(3) { ["one"]=> array(4) { [0]=> array(1) { [0]=> int(1) } [1]=> array(1) { [0]=> string(5) "jeden" } [2]=> array(1) { [0]=> string(4) "eins" } [3]=> array(1) { [0]=> string(3) "uno" } } ["two"]=> array(4) { [0]=> int(2) [1]=> string(3) "dwa" [2]=> string(4) "zwei" [3]=> string(3) "dos" } ["three"]=> array(4) { [0]=> int(3) [1]=> string(4) "trzy" [2]=> string(4) "drei" [3]=> string(4) "tres" } } object(sess)#2 (0) { } null end
as can see, object empty now
object(sess)#2 (0) { }
and first of property 'one' null instead array. wrong?
Comments
Post a Comment