Bug #77684 [NEW]: print with newline

From: Date: Fri, 01 Mar 2019 02:39:46 +0000
Subject: Bug #77684 [NEW]: print with newline
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219780@lists.php.net to get a copy of this message
From: svnpenn at gmail dot com Operating system: PHP version: 7.3.2 Package: *General Issues Bug Type: Bug Bug description:print with newline Description: ------------ with PHP, several methods are available to produce output: echo "hello world\n"; print "hello world\n"; print_r("hello world\n"); var_export("hello world\n"); However all these methods have something in common: they do not produce their own newline. With each method, the user is required to provide a newline with "\n", PHP_EOL or similar. This is bothersome because many other programming languages offer such a method. For example Python: print('hello world') Perl: use feature say; say 'hello world'; Ruby: puts 'hello world' Lua: print 'hello world' Even C: #include <stdio.h> int main() { puts("hello world"); } Out of the above examples, I would say Perl and Ruby are most similar to PHP, in that they also have the "print" method: $ perl -e 'print 2; print 3;' 23 $ ruby -e 'print 2; print 3;' 23 However even in this case, "print" can be made to produce a newline by default: $ perl -e '$\ = "\n"; print 2; print 3;' 2 3 $ ruby -e '$\ = "\n"; print 2; print 3;' 2 3 My request would be, in order of preference: 1. the "echo" method be modified such that it produces newline by default 2. new method method be added, perhaps "say", that produces newline by default 3. a variable be introduced, "$\" or similar, that controls output record separator I understand that some of these methods are decades old and unlikely to change, but if I do nothing then I have only myself to blame. -- Edit bug report at https://bugs.php.net/bug.php?id=77684&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77684&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77684&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77684&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77684&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77684&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77684&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77684&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77684&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77684&r=support Expected behavior: https://bugs.php.net/fix.php?id=77684&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77684&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77684&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77684&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77684&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77684&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77684&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77684&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77684&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77684&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77684&r=mysqlcfg

« previous php.bugs (#219780) next »