Re: [RFC] Property Accessors v1.2 : isset / unset "failable"

From: Date: Sun, 06 Jan 2013 18:13:01 +0000
Subject: Re: [RFC] Property Accessors v1.2 : isset / unset "failable"
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-64607@lists.php.net to get a copy of this message
Bringing up this old issue a bit. Nothing was ever said of unset? Should unset be benign? Since unset() is intended to take an action (rather than check on state) shouldn't an invalid unset (one with a guarded property that doesn't have a setter) emit a warning? On 10/30/2012 10:37 PM, Clint Priest wrote:
Would you say the same of unset? Always benign? On 10/29/2012 2:14 PM, Stas Malyshev wrote:
Hi!
So... to be explicit here, you think in this situation: class a {
    public $b {
       set($x) { $this->b = $x; }
    }
} $o = new a(); if(!isset($o->b)) {
    /* delete files */
} echo (int)isset($o->b); /* This should return false and not emit any sort of warning/notice? */
isset should return false, since $b is not set value. It should not produce any warning. Of course (int) would produce 0 then ;)
I mean specifically, there is no getter defined, therefore the result if isset is indeterminate and while I can see it not causing execution
No, the result is determinate - it's false. That's the point of isset() in PHP and that's how it is used in existing code.
to stop I don't see it being a good idea to not warn the developer that what they've attempted is not correct. Without a getter, isset() is not a legal call (since the value cannot be retrieved).
isset() should always be legal. This is the way to check if $o->b is legal.
-- -Clint

« previous php.internals (#64607) next »