NYCPHP Meetup

NYPHP.org

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

Jake McGraw jmcgraw1 at gmail.com
Sat Jul 19 21:17:19 EDT 2008


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

> I have a class that implements __get which retrieves the named
> attribute from a $this->_data array. In the past I believe I was able
> to do the following:
>
>  $a = &$this->a;


Could you post the code for your __get function? I think there are two
possible reasons for the discrepancy between 5.2.* and whatever version you
were running before:

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];
}

and removing the ampersand from the function call:

$a = $this->a;

or:

2. Perhaps the bug fix in 5.2.6 (see http://bugs.php.net/bug.php?id=43201)
changed the reference scheme.

- jake


>
>
> such that modifying array $a would be reflected in the underlying
> $this->_data array.
>
> However currently I'm using a machine with 5.2.6 and that code no longer
> works.
>
> If I change this to the following it works:
>
>  $a = &$this->_data['a'];
>
> This is not a big deal for me because the code in question is isolated
> within the class but I was wondering if something has changed or if
> I'm just mistaken or if there's an INI setting behind this?
>
> Any ideas?
>
> Mike
>
> --
> Michael B Allen
> PHP Active Directory SPNEGO SSO
> http://www.ioplex.com/
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080719/fcae5eec/attachment.html>


More information about the talk mailing list