On 14/03/2021 15:52, tyson andre wrote:
There's also the alias fputs ofhttps://www.php.net/manual/en/function.fwrite.php
which also returns the byte count.
Notably, like printf(), that is borrowed directly from C, and probably
dates from a time when most PHP programmers were also C programmers.
That time is long past.
Annoyingly, any decision I make would be inconsistent with something
I'm not sure why you're casting your net so wide. The name and use cases
for this function put it squarely next to "print" and "echo" in my mind,
and it would never occur to me to ask if it was consistent with most of
the functions you've mentioned.
It definitely would be longer to use `println((string)$foo)`,
but there may be cases where that would be done,
e.g. if you are writing a script that would be reviewed/modified/used by
programmers that are more familiar with languages that aren't PHP.
(It'd be more readable using 1 output method than 3)
Sorry, I'm not sure what you mean here. What 3 output methods are you
talking about, and how does println((string)$foo) make a difference to them?
There's also `println("$foo");`
Which is still marginally longer than the existing print "$foo\n";
Static analyzers for PHP such as Phan warn about the unused result of
multiplication
to catch cases like this, and other analyzers can easily add this check if they
don't already check for it.
https://github.com/phan/phan/wiki/Issue-Types-Caught-by-Phan#phannoopbinaryoperator
That doesn't stop it being a nasty surprise. People will want to use
"print" and "println" interchangeably, and making that difficult because
they have different syntax is going to end up on lists of "things I hate
about PHP", no matter how easily tools can spot it.
if ( something() && println($foo) && somethingElse() ) // does what it
looks like, if println is a normal function
if ( something() && print($foo) && somethingElse() ) // does not print
$foo, because the expression passed is actually ($foo)&&somethingElse()
The fact that `print` doesn't require parenthesis is something that surprised
me initially,
Just to be clear, it is not that print doesn't *require* parentheses,
it's that print does not have parentheses, ever.
though changing it to force it to use function syntax would be a much larger bc
break
more suitable for a major version, that I don't expect to pass.
It hadn't even occurred to me to suggest that. I was suggesting the
opposite: if we add something called "println", it should have identical
syntax and behaviour to "print". The only difference should be the extra
newline character in the output.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php