I'm trying to learn more about using the ArrayAccess interface.
I have one class (UserClass) creating an object that implements ArrayAccess (MyRecords). There is an array defined in UserClass that I wish to add to Records. For example, in UserClass:
The $records_array is getting passed into offsetSet but the problem is that the data passed into it isn't getting saved in the myRecords instance. The var_dump in offsetSet actually prints out the values defined in $records_array. In MyRecords:Code:$records_array = array ('name' => 'Bob', 'age' => '26'); $myRecords = new MyRecords(); $myRecords->offsetSet (0, $records_array);
Any idea why why the data isn't getting saved in MyRecords::data ??Code:private $data = array(); public function offsetSet ($offset, $value) { if (!is_numeric($offset)) { throw new Exception ("Key must be numeric"); } else { $this->data[$offset] = $value; var_dump ($value); } }


Reply With Quote

Bookmarks