On 15/02/2021 14:52, Matthew Brown wrote:
The most comparable example is between namespace separators:
Ns \ bar();
Ns \ SOME_CONST;
are both syntax errors.
As Sara says, this only became an error in 8.0, and there was a rather
specific reason for it, but I think there is a philosophical difference,
too.
"\" is part of a single piece of syntax: a fully-qualified class,
constant, or function name. You can't write $foo\Bar or Foo\$bar or
$foo\$bar.
"::" on the other hand is an operator that can be used in a variety of
ways. You can write $foo::bar(), Foo::$bar, $foo::$bar, {$foo .
'Handler'}::handle(), parent::foo(), and so on. It stands to reason that
it would have the same whitespace rules as any other operator.
I was surprised to learn that PHP treats :: similar to ->
I think it would be rather surprising if it *didn't* treat the two
operators similarly, since they're so closely related.
I wonder if there's a benefit to removing a small potential footgun from
the language?
I'm not really sure what the footgun here is. Adding newlines around
just about any operator you can think of will lead to code that confuses
at first glance:
$x = [
1,
2,
3,
4,
5
]
// Wait, we're not done yet...
[2];
Short of changing the entire language from semicolon-delimited to
newline-delimited, that's inevitable.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php