php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #69013 unclear/incomplete statement in echo documentation
Submitted: 2015-02-08 02:55 UTC Modified: 2015-12-18 22:19 UTC
From: teo8976 at gmail dot com Assigned: tpunt (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
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: teo8976 at gmail dot com
New email:
PHP Version: OS:

 

 [2015-02-08 02:55 UTC] teo8976 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.echo
---

"""
// Some people prefer passing multiple parameters to echo over concatenation.
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
"""

"Some people prefer"? And is or isn't there a reason for that?
According to http://www.mdproductions.ca/guides/50-best-practices-to-optimize-php-code-performance
the first is more efficient.

If that is true, it is of huge importance that it is mentioned ("Some people prefer .... because it's faster")
If it's not, then it's worth stating that it is a false myth ("Some people prefer... but it makes no difference")

In other words,
Either they are equivalent, in which case you should replace "Some people prefer" with "The following are equivalent" or "produce the exact same result", or they are not, in which case the differences or advantages (other than mere taste) of one over the other need to be clarified.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-18 21:50 UTC] tpunt@php.net
Automatic comment from SVN on behalf of tpunt
Revision: http://svn.php.net/viewvc/?view=revision&revision=338311
Log: Resolve doc bug #69013
 [2015-12-18 21:50 UTC] tpunt@php.net
-Assigned To: +Assigned To: tpunt
 [2015-12-18 22:18 UTC] tpunt@php.net
Automatic comment from SVN on behalf of tpunt
Revision: http://svn.php.net/viewvc/?view=revision&revision=338312
Log: Resolve doc bug #69013 with additional information
 [2015-12-18 22:19 UTC] tpunt@php.net
It may be a micro-optimisation (I haven't personally done an artificial benchmark for it, though :), but the actual benefit to passing in multiple arguments over concatenation actually concerns the precedence of the period operator in PHP. If you'd like to use other operators in the expression (like the ternary operator), then with concatenation, you'll need to enforce precedence using parentheses:
echo "Hello " . (isset($name) ? $name : "John Doe") . "!";
Versus:
echo "Hello ", isset($name) ? $name : "John Doe", "!";

I've resolved this with commits:
https://svn.php.net/viewvc?view=revision&revision=338311
https://svn.php.net/viewvc?view=revision&revision=338312
 [2015-12-18 22:19 UTC] tpunt@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC