Re: Re: [VOTE] [RFC] Alphanumeric Decrement

From: Date: Tue, 28 Jan 2014 06:12:33 +0000
Subject: Re: Re: [VOTE] [RFC] Alphanumeric Decrement
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-71658@lists.php.net to get a copy of this message
Hi, On Tue, Jan 28, 2014 at 10:51 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: > Hi Tjerk, > > On Tue, Jan 28, 2014 at 10:39 AM, Tjerk Meesters <tjerk.meesters@gmail.com > > wrote: > >> I still have an RFC lying around that suggests this, together with some >> other changes to how increment / decrement works. Perhaps we could flesh >> this out further? >> >> https://wiki.php.net/rfc/normalize_inc_dec >> > > The following behaviour is proposed: > > // booleans > $a = false; ++$a; // bool(true) > $a = true; --$a; // bool(false) > > // null values > $a = null; --$a; // null > $a = null; ++$a; // null > > // empty strings > $a = ''; ++$a; // int(1) > > // non-numeric strings > $a = '12d9'; > ++$a; // string(4) "12e0" + Notice: String increment is deprecated, use > str_inc() instead in php shell code on line 1 > ++$a; // float(13) > > +1 especially boolean++/--. > It's great for flip flop. I guess most users use int++ and int%2 for flip > flop currently. > Existing scripts using ++/-- against bool would be a bug most likely. > The RFC doesn't mention this, but the intended behaviour is that `$a = true; ++$a; yields bool(true)`, i.e. no overflow ... however, I'm open to the suggestion to make it "overflowable", like integer values. Btw, doing flip/flop can be done with $val = (bool)1 - $val; as well :) > > Other proposal sounds reasonable to me, too. > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > -- -- Tjerk

« previous php.internals (#71658) next »