dynamic/multidimensional arrays in classes

From: Date: Mon, 10 Mar 2003 06:56:00 +0000
Subject: dynamic/multidimensional arrays in classes
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-138922@lists.php.net to get a copy of this message
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

« previous php.general (#138922) next »