note 89379 rejected from language.operators.logical by danbrown

From: Date: Thu, 05 Mar 2009 17:00:43 +0000
Subject: note 89379 rejected from language.operators.logical by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151529@lists.php.net to get a copy of this message
Note Submitter: e dot sand at elisand dot com ---- It should be noted that despite what it may look like to some people, you *cannot* imitate Javascripts shorthand assignment notation (which is similar to ternary notation, though it omits the middle part). In JavaScript, you can write: var text_var = some_var || new String(); That will assign some_var to text_var if it's a "true" statement (aka, if (some_var) would be true), otherwise it would assign text_var a new String() object. The PHP documentation gives the slight appearance as if writing: $text_var = $some_var or new String(); would do the same thing, however it does not - and it's too bad, because it would be useful and more readable than the new shorthand ternary format, valid for PHP 5.3+ only: $text_var = $some_var ?: new String(); Unfortunately, it appears that once the "or" condition is seen, it forgets what context it was in and expects a completely new statement for evaluation, rather than a continuation (as is possible in JavaScript).

« previous php.notes (#151529) next »