ate: Monday, Nov 24, 2008 2:14 pm
Subject: [nyphp-talk] passing array/object data
To: talk - nyphp Reply-To: NYPHP Talk
I have a method that takes a parameter that might be either an array or
>a db result object. So on the one hand I might have:
>echo $array['stuff'];
>or o
echo (object)$data->something
or even better, wrap the whole thing in a 'result object'..
class resultObject {
protected $data = array();
public function __construct($data)
{
$this->data = (array)$data;
}
public function __get($k) {
return (isset($this->data[$k])) ? $this->data[$k] : n
I have a method that takes a parameter that might be either an array or
a db result object. So on the one hand I might have:
echo $array['stuff'];
or on the other:
echo $result -> stuff;
Right now I'm just using is_array and repeated brute force to do this,
but obviously there's a better way. W