Re: [RFC] anti-coalescing-operator

From: Date: Thu, 24 Oct 2019 21:30:36 +0000
Subject: Re: [RFC] anti-coalescing-operator
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-107672@lists.php.net to get a copy of this message
Hi Bruce If I understand correctly. $_SERVER['fname'] !?? $user->setName($_SERVER['fname']); Will return the result of $user->setName($_SERVER['fname']) if $_SERVER['fname'] is set or null if not set. While: isset($_SERVER['fname']) && $user->setName($_SERVER['fname']); Will return boolean. Cheers On Fri, Oct 25, 2019 at 4:24 AM Bruce Weirdan <weirdan@gmail.com> wrote: > Hi Ken > > > $_SERVER['fname'] !?? $user->setName($_SERVER['fname']); > > $_SERVER['lname'] !?? $user->setName($_SERVER['lname']); > > $_SERVER['mname'] !?? $user->setName($_SERVER['mname']); > > $_SERVER['phone'] !?? $user->setName($_SERVER['phone']); > > $_SERVER['email'] !?? $user->setName($_SERVER['email']); > > What you described is already achievable with short-circuit && : > > isset($_SERVER['fname']) && $user->setName($_SERVER['fname']); > > Besides, it's a widely used idiom known from shell scripting. > > -- > Best regards, > Bruce Weirdan mailto: > weirdan@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.internals (#107672) next »