sunnyside
04-24-2007, 03:05 PM
I have a class which has a constructor with an array variable as argument. I can get the correct each array value inside of the constructor, but won't get it outside of the constructor (always get "A", "1" as the each array value).
Code:
function myfunction(
$dataField['a'] = $a;
$dataField['b'] = $b;
$dataField['c'] = $c;
$obj = new MyClass($dataField);
}
class MyClass{
private $myArray = array();
public function __constructor($arrString=array()){
$this->myArray = $arrString;
print_r($this->myArray); // no problem to get all values
}
public function testArray(){
return $this->myArray['a']; /* won't print out "a", display "1", "A", something like that */
}
}
Code:
function myfunction(
$dataField['a'] = $a;
$dataField['b'] = $b;
$dataField['c'] = $c;
$obj = new MyClass($dataField);
}
class MyClass{
private $myArray = array();
public function __constructor($arrString=array()){
$this->myArray = $arrString;
print_r($this->myArray); // no problem to get all values
}
public function testArray(){
return $this->myArray['a']; /* won't print out "a", display "1", "A", something like that */
}
}