1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php class example { public $array; public function __construct() { $this->array = array(); } public function do_work() { $this->array[] = 'test'; } } $test = new example(); $test->do_work(); echo $test->array . "\n"; var_dump($test->array);
1 2 3 4 5
Array array(1) { [0]=> string(4) "test" }