|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-08-25 09:14 UTC] rasmus@php.net
-Status: Open
+Status: Bogus
[2010-08-25 09:14 UTC] rasmus@php.net
[2010-08-25 09:24 UTC] biolizard dot mail at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 06:00:02 2025 UTC |
Description: ------------ The logical operator 'or' and the operator '||' produce different values, which is inconsistent with the description and the examples presented in the PHP website. However, when returning from a function, the inconsistency is even more problematic. The operator 'or', when used in a statement (e.g., assignment), returns the first value that is not false. However, when used as a return expression the returned value is either true or false. Test script: --------------- <?php function f() { return 'ola' || 'adeus'; } function p() { return 'ola' or 'adeus'; } $a = 'ola' || 'adeus'; $b = 'ola' or 'adeus'; echo $a . "\n"; echo $b . "\n"; echo f() . "\n"; echo p() . "\n"; ?> Expected result: ---------------- 1 ola 1 ola Actual result: -------------- 1 ola 1 1