Re: Property Accessors 1.2 for Final Review before Vote

From: Date: Thu, 03 Jan 2013 00:28:43 +0000
Subject: Re: Property Accessors 1.2 for Final Review before Vote
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 1/2/13 6:08 PM, Clint Priest wrote:
Sorry, there was a typo in that RFC there, this line:
         isset { return $this->Hours != NULL; }
Should have been with !==:
         isset { return $this->Hours !== NULL; }
I've already updated the 1.2 doc to reflect the correct way. Given what I mentioned above, I'm assuming you did not test this with the fork, right? Just based your comments on how it should logically work (with the incorrect != vs !==?)
I haven't tested the fork. I just borrowed your logic with the typo :)
One last thing about that, the isset/unset with $this->Hours calls the getter to retrieve the $this->Hours value, so it behaves as your example below indicates.
The RFC says, "only the accessors themselves may directly access the shadowed property." I read that as: Within get, $this->Hours is the raw shadowed property. Within set, $this->Hours is the raw shadowed property. Within isset, $this->Hours is the raw shadowed property. Within unset, $this->Hours is the raw shadowed property. But you seem to imply: Within get, $this->Hours is the raw shadowed property. Within set, $this->Hours is the raw shadowed property. Within isset, $this->Hours is accessed via __getHours()/__setHours(). Within unset, $this->Hours is accessed via __getHours()/__setHours(). So really the default implementations behave like this: isset { return $this->__getHours() !== NULL; } unset { $this->__setHours(NULL); } I think the RFC should be much clearer about what property access actually means within each accessor method, as I expect users to be very surprised by this behavior. This is also looks like it could lead to surprises: Within get, $this->Hours is the raw shadowed property. Within get, parent::$Hours is accessed via parent::__getHours()/parent::__setHours(). Also, is there no way to access the shadow property within isset/unset? If not, is there a good reason to not allow it? Also, do/should multiple property accessors interact? Consider: class Foo {
    public $a {
        get { $this->a = 1; return 2; }
    }
    public $b {
        get { return $this->a; }
    }
} $foo = new Foo; $foo->a; // 2 (but shadowed property is 1) $foo->b; // 1 or 2? Steve Clay -- http://www.mrclay.org/

Thread (52 messages)

« previous php.internals (#64490) next »