[nycphp-talk] passing array/object data
Elijah Insua
tmpvar at gmail.com
Mon Nov 24 14:36:20 EST 2008
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] : null;
}
}
hope it helps,
Elijah Insua
On Mon, Nov 24, 2008 at 2:14 PM, Michael Southwell <
michael.southwell at nyphp.com> wrote:
> 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. What's my best way to abstract this so I can
> use just one echo statement regardless of the parameter?
> --
> =================
> Michael Southwell
> Vice President, Education
> NYPHP TRAINING: http://nyphp.com/Training/Indepth
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20081124/1870617f/attachment.html>
More information about the talk
mailing list