Bug #76414 [Com]: return echo("foo"); ought to work as expected

From: Date: Tue, 05 Jun 2018 11:53:17 +0000
Subject: Bug #76414 [Com]: return echo("foo"); ought to work as expected
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215501@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76414&edit=1 ID: 76414 Comment by: spam2 at rhsoft dot net Reported by: aleemb at gmail dot com Summary: return echo("foo"); ought to work as expected Status: Not a bug Type: Bug Package: *General Issues Operating System: OSX PHP Version: 7.2.6 Block user comment: N Private report: N New Comment: http://php.net/manual/en/function.echo.php echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses. Previous Comments: ------------------------------------------------------------------------ [2018-06-05 11:36:29] aleemb at gmail dot com I was assuming since neither are language constructs, they could share the same "return" semantics. Your explanation, however, helps clarify that. Thanks for taking the time to highlight it, learnt something new. ------------------------------------------------------------------------ [2018-06-05 11:36:01] yohgaki@php.net Since echo is not a function, you cannot do $var ? echo 'abc' : echo 'xyz'; also. It's not a function, so echo wouldn't return absolutely nothing. Therefore, it cannot be used anywhere expression is expected. ------------------------------------------------------------------------ [2018-06-05 11:31:06] requinix@php.net > is there any reason echo can't be tweaked to behave in the same manner? Because there's no reason to? echo and print are both doing exactly what they're intended to do. ------------------------------------------------------------------------ [2018-06-05 11:20:57] spam2 at rhsoft dot net echo is *not* a function - it's a language costruct echo $a, "\n", $b, "\n"; this would not be possible with a function and the difference is that is saves a ton of concat calls compared to echo $a. "\n" . $b . "\n" which does exactly the same but becaus eof the repeatet concat a ton of in-memory-copies a triggered which can be expensive depending on the string sizes ------------------------------------------------------------------------ [2018-06-05 11:16:16] aleemb at gmail dot com @requinix, is there any reason echo can't be tweaked to behave in the same manner? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=76414 -- Edit this bug report at https://bugs.php.net/bug.php?id=76414&edit=1

« previous php.bugs (#215501) next »