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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chris at candm dot org dot uk
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2023 The PHP Group
All rights reserved.
Last updated: Sat Feb 04 16:05:48 2023 UTC