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

From: Date: Wed, 31 Oct 2012 03:37:03 +0000
Subject: Re: [RFC] Property Accessors v1.2 : isset / unset "failable"
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-63728@lists.php.net to get a copy of this message
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 (#63728) next »