Edit report at https://bugs.php.net/bug.php?id=60694&edit=1
ID: 60694 Comment by: phpmpan at mpan dot pl Reported by: MarkAndrewSlade at gmail dot com Summary: print() results in bad logic Status: Open Type: Bug Package: Scripting Engine problem Operating System: CentOS release 5.4 (Final) PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Invalid interpretation of the code caused by misleading parenthenses. 1. false && print ('') -> false && (print ('')) -> false && 1 -> false 2. print('') && false -> (print (('') && false)) -> (print false) -> 1 -> true 3. print('') && false && false -> (print ((('') && false) && false)) -> (print false) -> 1 -> true 4. (print('') && false) && true -> ( print (('') && false) ) && true -> (print false) && true -> 1 && true -> true 5. (print('') && false) && false -> (print (('') && false) && false -> (print false) && false -> 1 && false -> false I believe that documentation for all language constructs (`echo`, `include`, `print`, ...) should explicitly discourage use of parenthenses around arguments. They're very misleading. Previous Comments: ------------------------------------------------------------------------ [2012-01-10 02:26:21] MarkAndrewSlade at gmail dot com Description: ------------ Unlike echo, the print construct is allowed inside logic clauses. If it is reached (not short-circuited), it will cause the rest of that clause to be true. Tested with 5.3.8 and PHP 5.3.9RC5-dev, both with default configure. Test script: --------------- <?php echo (false && print('')) ? "Fail\n" : "Pass\n"; echo (print('') && false) ? "Fail\n" : "Pass\n"; echo (print('') && false && false) ? "Fail\n" : "Pass\n"; echo ((print('') && false) && true) ? "Fail\n" : "Pass\n"; echo ((print('') && false) && false) ? "Fail\n" : "Pass\n"; ?> Expected result: ---------------- The word "Pass" five times. Actual result: -------------- The middle three fail. The first and last pass, and are included to demonstrate the limits of the bug. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60694&edit=1