Re: not_null function

From: Date: Fri, 04 Jul 2014 21:26:44 +0000
Subject: Re: not_null function
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-75253@lists.php.net to get a copy of this message
On Fri, Jul 4, 2014 at 2:27 PM, Xen <xen@dds.nl> wrote: > Op Fri, 04 Jul 2014 14:34:17 +0200 schreef Robert Stoll <php@tutteli.ch>: > > >> [Robert Stoll] >> >> I really like how ruby tackles this problem with the syntactic sugar >> "unless" which basically is a substitute for "if( !() )". >> Maybe we could consider to introduce it in PHP next? It is very natural to >> read "unless(is_null($x))" an much nicer than "if(!is_null($x)" IMO. >> And it >> would not only solve your issue with is_null but is_Xy functions/methods in >> general. > > > I think that is just flawless. Thank you SO much for suggesting this. For completeness, it is available in Perl and I believe Perl had it first; not completely sure though. > Because you still have the cross-contamination between isset and is_null. > People wrongly use "isset" to test for "is set and is not null". So you > would have to keep is_null as meaning "if it is not set or (if it is set) > it is null". > > "unless (is_null())" would then mean "unless (!isset || is_null)" but it > would definitely be better than abusing isset for this. I don't think changing isset would be beneficial, sadly. I wish it only checked that a variable exists and didn't do the not null check but it's used very, very widely.

« previous php.internals (#75253) next »