note 79081 deleted from language.oop5.overloading by levim

From: Date: Mon, 16 Nov 2015 02:03:26 +0000
Subject: note 79081 deleted from language.oop5.overloading by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-204159@lists.php.net to get a copy of this message
Note Submitter: anthony dot parsons at manx dot net ---- You can't use __set to set arrays, but if you really want to, you can emulate it yourself: <?php class test { public $x = array(); public $y = array(); function __set($var, $value) { if ( preg_match('/(.*)\[(.*)\]/', $var, $names) ) { $this->y[$names[1]][$names[2]] = $value; } else { $this->x[$var] = $value; } } } $z = new test; $z->variable = 'abc'; $z->{'somearray[key]'} = 'def'; var_dump($z->x); var_dump($z->y); ?>

« previous php.notes (#204159) next »