note 89379 added to language.operators.logical
| From: | e dot sand at elisand dot com | Date: | Thu, 05 Mar 2009 06:20:32 +0000 |
| Subject: | note 89379 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151504@lists.php.net to get a copy of this message | ||
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).
----
Server IP: 69.147.83.197
Probable Submitter: 99.241.132.158
----
Manual Page -- http://www.php.net/manual/en/language.operators.logical.php
Edit -- https://master.php.net/note/edit/89379
Del: integrated -- https://master.php.net/note/delete/89379/integrated
Del: useless -- https://master.php.net/note/delete/89379/useless
Del: bad code -- https://master.php.net/note/delete/89379/bad+code
Del: spam -- https://master.php.net/note/delete/89379/spam
Del: non-english -- https://master.php.net/note/delete/89379/non-english
Del: in docs -- https://master.php.net/note/delete/89379/in+docs
Del: other reasons-- https://master.php.net/note/delete/89379
Reject -- https://master.php.net/note/reject/89379
Search -- https://master.php.net/manage/user-notes.php