should be
$this->arr[]
You are using a variable defined within the class - since it is a class variable you can reference it as you would anything else within the class, using '$this->'
Patrick Teague wrote:
I'm having problems figuring this out. This first way gives me a 'Fatal Error: Cannot use [] for reading in class.php on line xx'
class myClass { var $arr = array();
function add_something( $value ) { $this->$arr[] = $value; // this is the line causing the error } }
I've also tried using count() to find out how many items are in $arr, but it keeps saying that $r == 0... i.e.
function add_something( $value ) { $r = count($arr); /* if( is_null( $r ) { $r = 0; } */ //print( $r ); $this->$arr[$r] = $value; }
I've tried this both with & without the commented section & still $r = 0 even if you use '$class->add_something("my value");' 50 times. I'm guessing once this problem is solved it will work for multidimensional arrays as well?
Patrick
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php