My primary reason for using call is to avoid creating, deleting, modifying a myriad a of get/set methods whose only purpose in life is to return, or set a primitive property. I want to avoid using __set, __get for reasons I give in the link to my webpage.
If you take a peek at the Jon Levensold videos (the end of video # 5, and beginning of video # 6) this precisely what he does.
After watching the two videos above I found this:
This shows the code on my webpage:
This is a comment from the code in the previous link, which summarizes the problem.
/** * __call as I have set it up below, can set variable primitive types, as well * as arrays, but can only return primitives (no arrays) as I currently have it * setup. I did not want to use __set and __get, I wanted to use __call only. * * looking at the colors property which contains a multi-dimensional array * * Using __call overloading as defined here: * * you can set a primitive using : $storage->setBr("<br>"); * you can get a primitive using : echo $storage->getBr(); * * you can set an array such as $colors as shown on the next line: * $storage->setColors * ( * array * ( * 'foreground' => array * ( * "header" => "black", * "block" => "orange", * "body" => "black", * <snip> ... </snip> * ) * ) * ); // End of : $storage->setColors * * you can get any of the elements in the multi-dimensional array as follows: * echo "$storage->getColors('foreground')->getBody(); // returns "black" * * THE REAL PROBLEM THAT I HAVE: * * I cannot retrieve an entire array using __call, by calling: * * $aObj = $storage->getUsers(5)->getBooks(1); // fails to return the array * $aArray = (array) $aObj; // casting to array does not help * * I had to create a specific method: public function getBookArray($user_no, $book_no) * in order to retrieve the entire array, something I did not want to do. I was hoping * to be able to do both set/get using __call and only create specific methods whenever * internal calculations, or changing other affected variables, or other actions need * to be taken. * * The $message_no's are temporary until I come up with a finished version. */
I can with the code I have so far at:
( 1 ) set/retrieve primitives,
( 2 ) set arrays,
( 3 ) set and retrieve elements of an array,
( 4 ) but cannot figure out using __call how to retrieve entire arrays.
I would be grateful for any help.