note 129994 added to language.operators.comparison
| From: | billynoah@gmail.com | Date: | Wed, 22 Jan 2025 18:14:53 +0000 |
| Subject: | note 129994 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221810@lists.php.net to get a copy of this message | ||
It's worth noting that there can be a difference in the logical operation of shorthand ternary
(expr1 ?: expr2) vs the full version (expr1 ? expr1 : expr2). The shorthand style may also offer a
slight performance enhancement because the initial expression will only be evaluated once.
Example:
<?php
// my_func() will be called twice here
// additionally, my_func() may not return the same value both times!
$var = my_func() ? my_func() : false;
// my_func() will only be called once here
$var = my_func() ?: false;
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.84.18 (proxied: 24.180.65.101)
----
Manual Page -- https://php.net/manual/en/language.operators.comparison.php
Edit -- https://main.php.net/note/edit/129994
Del: integrated -- https://main.php.net/note/delete/129994/integrated
Del: useless -- https://main.php.net/note/delete/129994/useless
Del: bad code -- https://main.php.net/note/delete/129994/bad+code
Del: spam -- https://main.php.net/note/delete/129994/spam
Del: non-english -- https://main.php.net/note/delete/129994/non-english
Del: in docs -- https://main.php.net/note/delete/129994/in+docs
Del: other reasons-- https://main.php.net/note/delete/129994
Reject -- https://main.php.net/note/reject/129994
Search -- https://main.php.net/manage/user-notes.php