Re: [RFC] unset(): return bool if the variable has existed

From: Date: Thu, 07 Mar 2013 08:54:02 +0000
Subject: Re: [RFC] unset(): return bool if the variable has existed
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 7 March 2013 09:45, Sebastian Krebs <[email protected]> wrote:

>
> So I guess this is the only useful behaviour. However, I have no idea, what
> this information should tell me. If I call unset() then I want to ensure,
> that the variable is not set anymore, but for what reason I should need to
> know, whether it was set before, or not?
>

I think I actually had an use case with proxies, where I wanted to know if
a property was set or not. That's useful to reset the proxy state
(basically to intercept property access) and differentiate null properties
vs non existing properties:

    class Blah extends Blubb
    {
        protected $prop;
        public function __construct() { unset($this->prop); }
        public function init() { $this->prop = 'stuff'; }
        public function reset() { return unset($this->prop); } // we now
know if init was called
    }

This *could* be useful if I want to keep track of the state of a proxy, but
it's just an additional property to keep track of manually on the other
side. The additional property is also more explicit and easier to track.

Yes, it needs a better use case.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


Thread (21 messages)

« previous php.internals (#66518) next »