note 92595 deleted from overload.examples.basic by thiago
| From: | thiago@php.net | Date: | Thu, 30 Jul 2009 18:13:14 +0000 |
| Subject: | note 92595 deleted from overload.examples.basic by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158929@lists.php.net to get a copy of this message | ||
Note Submitter: Benjamin [falk at citrosaft dot com]
----
When I try to overload a variable, which value is an array, the overloading won't take any
effect (PHP gives me a notice-message)
<?php
$c = new OverloadedClass;
$c->myArray = array();
function add($value)
{
global $c;
$c->myArray[] = $value;
}
add('element1');
add('element2');
?>
This doesn't work. And if this array, already got some elements, this is really going mad.
My dirty workaround is this one right now:
<?php
$c = new OverloadedClass;
$c->myArray = array();
function add($value)
{
global $c;
$c->myArray = array_merge($c->myArray, array($value));
}
add('element1');
add('element2');
?>
Is there a better way to do that?