php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81329 echo misbehaves when there is a ternary operator
Submitted: 2021-08-04 01:29 UTC Modified: 2021-08-04 04:08 UTC
From: chris at candm dot org dot uk Assigned:
Status: Not a bug Package: Strings related
PHP Version: 7.4.22 OS: Linux Mint 20 Apache 2.4.1
Private report: No CVE-ID: None
 [2021-08-04 01:29 UTC] chris at candm dot org dot uk
Description:
------------
When using echo, if a ternary is concatenated after a string, the string is not echoed, only the result from the ternary.

PHP version 7.4.3
Apache Version	Apache/2.4.41 (Ubuntu)
Apache API Version	20120211
Linux Kernel: 5.8.0-63-generic x86_64 bits: 64 
Desktop: Cinnamon 4.8.6 
Linux Mint 20.1 Ulyssa base: Ubuntu 20.04
Machine: Acer Aspire A515-55 v: V1.08

Test script:
---------------
<?php
echo "THIS SHOULD SHOW ".(true)?'true':'false';


Expected result:
----------------
Result:
THIS SHOULD SHOW true

Actual result:
--------------
Result
true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-04 04:08 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-08-04 04:08 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

https://www.php.net/manual/en/language.operators.precedence.php
The concatenation '.' operator has higher precedence than the ternary ? : operator.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 15:01:32 2024 UTC