PHP7 Coalesce operator

From: Date: Sun, 22 Nov 2015 09:15:41 +0000
Subject: PHP7 Coalesce operator
Groups: php.internals 
Request: Send a blank email to internals+get-89292@lists.php.net to get a copy of this message
Hey all. Been a while since I popped into this list. You may remember me from such emails as “Why god can’t we have namespaces”, or “so we’re still not fixing strpos, eh?” I had a question-suggestion based around the cool new operator we’re getting in PHP7, the ?? operator, which as I understand it is the functional equivalent to perl’s // operator; in that they both test for whether or not a variable is defined, rather than it’s truthiness. That’s all well and good, but one of the things that makes the || operator in javascript so handy is that definedness and truthiness go hand in hand, and an undefined value will simply evaluate to null/false, making things like (foo || false || true) possible, which is quite handy in a lot of situations. It seems like if we already have a construct in place that’ll bypass raising an E_NOTICE, it should possible to implement a secondary operator that tests for truthiness with similar semantics. Something like, $config->auto_play = $config->auto_play ?! $defaults->auto_play ?! false; Do you feel me? Guys? -M

« previous php.internals (#89292) next »