note 92595 added to overload.examples.basic

From: Date: Thu, 30 Jul 2009 18:03:46 +0000
Subject: note 92595 added to overload.examples.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-158928@lists.php.net to get a copy of this message
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? ---- Server IP: 212.69.189.114 Probable Submitter: 90.146.174.186 ---- Manual Page -- http://www.php.net/manual/en/overload.examples.basic.php Edit -- https://master.php.net/note/edit/92595 Del: integrated -- https://master.php.net/note/delete/92595/integrated Del: useless -- https://master.php.net/note/delete/92595/useless Del: bad code -- https://master.php.net/note/delete/92595/bad+code Del: spam -- https://master.php.net/note/delete/92595/spam Del: non-english -- https://master.php.net/note/delete/92595/non-english Del: in docs -- https://master.php.net/note/delete/92595/in+docs Del: other reasons-- https://master.php.net/note/delete/92595 Reject -- https://master.php.net/note/reject/92595 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158928) next »