Re: print with newline
| From: | Johannes Schlüter | Date: | Sat, 02 Mar 2019 22:15:49 +0000 |
| Subject: | Re: print with newline | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104546@lists.php.net to get a copy of this message | ||
On Sa, 2019-03-02 at 11:59 -0800, Steven Penny wrote:
> 1. Modify one or more of "print", "print_r", "var_export" such
> that
> they produce
> a newline by default
This is a break of backwards compatibility in a bad way. This breaks
people doing specific output.
> 2. Modify one or more of "print", "print_r", "var_export" such
> that
> they have an
> argument similar to Python "end" that controls what follows the
> input, if
> anything:
>
> https://docs.python.org/library/functions.html#print
PHP's echo has the option already:
echo $foo, PHP_EOL;
not much difference i effort to writing
print $foo, true;
except that the code is explicit.
> 3. Add a new method, perhaps "echoln", "println", "say" or
> similar,
> that outputs
> a newline by default
function println($a) {
echo $a, PHP_EOL;
}
Can easily be done in library.
> 4. introduce a new variable, perhaps "$OUTPUT_RECORD_SEPARATOR",
> "$ORS", "$\" or
> similar, that controls output record separator
Such magic is hard to debug and easily leads to bugs in user code.
While sometimes having a shortcut at hand is nice, next request will be
to automatically add a "<br>" as we often produce HTML and thn the ex
request and next and this becomes messy and making everything harder
for very little benefit.
johannes