NYCPHP Meetup

NYPHP.org

[nycphp-talk] Change in magic method + reference behavior?

Jake McGraw jmcgraw1 at gmail.com
Sun Jul 20 08:55:31 EDT 2008


On Sat, Jul 19, 2008 at 11:55 PM, Michael B Allen <ioplex at gmail.com> wrote:

> On Sat, Jul 19, 2008 at 10:55 PM, Jake McGraw <jmcgraw1 at gmail.com> wrote:
> >
> >> > 1. You're using "Call-time pass-by-reference" by marking your return
> >> > value
> >> > with an ampersand, try changing your code to this:
> >> >
> >> > public function __get($field) {
> >> >   return &$this->_data[$field];
> >> > }
> >>
> >> But I don't want the default behavior to be to return a reference.
> >>
> >> Mike
> >
> > Ah, well, you're setting yourself up for some fun debugging later on,
> it's
> > probably best not to mix and match pass by reference/value, which is why
> I
> > think the PHP group depreciated the ability to do call-time pass by
> > reference. IMO, whether a function returns a reference or a value should
> be
> > part of the object method definition, not on the basis of the way the
> > function was called.
>
> I did not use, do not use and do not want to use call-time
> pass-by-reference.


> The code in question was "&$this->a" where $this is "magic" so it
> should, in theory, behave as though "a" was a real object member.


Ahhhhh... sorry, that's what I get for having a programming conversation
late on a Saturday night.

- jake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080720/5a85fd95/attachment.html>


More information about the talk mailing list