Sara, where do I send pull requests?
<?php
function println(string $format, ...$args) : void {
\vprintf($format . \PHP_EOL, $args);
}
function fprintln($stream, string $format, ...$args) : void {
if (!\is_resource($stream)) {
throw new \TypeError(\sprintf(
"Argument 1 passed to %s expected to be a resource, %s given",
__FUNCTION__,
\is_object($stream) ?
\sprintf(
"instance of %s", \get_class($stream)
) : \gettype($stream)));
}
\vfprintf($stream, $format . \PHP_EOL, $args);
}
function sprintln(string $format, ...$args) : string {
return \vsprintf($format . \PHP_EOL, $args);
}
Jokes aside, this is so trivially achievable in userland that there is no
justification whatever for an internal function or functions, or
constructs, or opcodes.
Cheers
Joe
On Sun, 3 Mar 2019 at 06:50, Ryan Jentzsch <[email protected]> wrote:
> I've always wondered why PHP didn't have a built in command or function
> that behaved as `echo` but with a EOL.
> I propose not to modify `print` or `echo` (as this was rightly pointed out
> to cause b/c). How difficult would it be to add a new statement and/or
> function to the PHP core called `say` / `say()` that has an EOL?
>
> This seems to me to be simple to do. The benefit is less code to type in
> user land (ex: `say 'Hello World';` as opposed to `echo 'Hello World' .
> PHP_EOL;`
>