Req #74362 [Wfx]: Make echo and print equivalent

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=74362&edit=1

 ID:                 74362
 Updated by:         [email protected]
 Reported by:        olafvdspek at gmail dot com
 Summary:            Make echo and print equivalent
 Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

True about the difference being slightly larger, but as far as the original question goes: Yes, we could allow print to accept multiple arguments.

For that matter we could make echo return a value.  Neither is going to break anything[citation needed], and due to the way the compiler handles both statements, neither will perform worse (fun fact: the compiler turn both into ZEND_ECHO opcodes, just with a different extended_value which it doesn't even use).

Should we? It'd be a grammar change, so you'll need an RFC and a 2/3 vote in favor of it.  Without a compelling reason, I doubt you'll get that.


Previous Comments:
------------------------------------------------------------------------
[2017-04-02 15:33:01] [email protected]

Small example:

foo(print 1, 2);
^ is 2 a second argument to print or to foo?

That's ambiguous, hence we do not allow that.

------------------------------------------------------------------------
[2017-04-02 13:22:05] olafvdspek at gmail dot com

> That's not the only difference,

OK, so the documentation is wrong too?

@dm: sure, but that doesn't mean print couldn't support multiple arguments does it?

------------------------------------------------------------------------
[2017-04-02 13:03:11] [email protected]

`print` has a return value along with outputting and can be used as e.g. `return print json_encode(...);` while `echo` can not.

------------------------------------------------------------------------
[2017-04-02 12:45:54] [email protected]

That's not the only difference, the return types also vary. "echo" is "void" while "print" returns "int".

------------------------------------------------------------------------
[2017-04-02 12:42:39] olafvdspek at gmail dot com

Description:
------------
Could print be made equivalent to echo such that it accepts multiple arguments?

> The only difference to print is that echo accepts an argument list.
> The only difference to echo is that print only accepts a single argument.

http://php.net/echo
http://php.net/print

Test script:
---------------
<?php
echo('A', 2, 'C');
print('A', 2, 'C');

Actual result:
--------------
-


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74362&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.