I am looking for a way to intercept the action in array_push
, because when it will be retrieve it each value of the array has another info like:
class ClassName {
var $test = array();
function __set($attr, $value) {
$this->$attr = 'My extra value'.$value;
}
function index(){
array_push($this->test, "some val");
array_push($this->test, "some other val");
print_r($this->test);
}
}
$o = new ClassName();
$o->index();
And expected to get something like:
Array
(
[0] => My extra value some val
[1] => My extra value some other val
)
But i get:
Array
(
[0] => some val
[1] => some other val
)
Thanks to all
$test
property ofClassName
. The code he has does not work. – Rocket Hazmat Apr 10 '12 at 18:14test
is public therefore accessible so__set()
won't be called. I'm not 100% certain but internally PHP might call get on yourtest
property first.. append the value witharray_push()
then call set with the new value. Not sure if that helps.. just a hidden behavior of php. – Mike B Apr 10 '12 at 18:15test
private (private $test
), but still, php doesnt get in to the __set function – user115561 Apr 10 '12 at 18:23