note 79081 added to language.oop5.overloading
| From: | anthony dot parsons at manx dot net | Date: | Fri, 09 Nov 2007 22:57:35 +0000 |
| Subject: | note 79081 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132153@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 194.145.210.3
Probable Submitter: 87.254.70.8
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/79081
Del: integrated -- https://master.php.net/note/delete/79081/integrated
Del: useless -- https://master.php.net/note/delete/79081/useless
Del: bad code -- https://master.php.net/note/delete/79081/bad+code
Del: spam -- https://master.php.net/note/delete/79081/spam
Del: non-english -- https://master.php.net/note/delete/79081/non-english
Del: in docs -- https://master.php.net/note/delete/79081/in+docs
Del: other reasons-- https://master.php.net/note/delete/79081
Reject -- https://master.php.net/note/reject/79081
Search -- https://master.php.net/manage/user-notes.php