Re: Whitespace around Paamayim Nekudotayim (double colon)
| From: | Stephen Reay | Date: | Mon, 15 Feb 2021 05:50:29 +0000 |
| Subject: | Re: Whitespace around Paamayim Nekudotayim (double colon) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-113175@lists.php.net to get a copy of this message | ||
> On 15 Feb 2021, at 12:14, Matthew Brown <matthewmatthew@gmail.com> wrote:
>
> Hey all,
>
> Is there interest in prohibiting whitespace around double colons in the
> next major PHP version?
>
> I was surprised to learn that PHP treats :: similar to ->, allowing double
> colons like
>
> A::
> b();
>
> Looking at the top 2,000 packages in Packagist I can't find any evidence of
> people using a double colon with whitespace around, and my suspicion is
> that the use of it is basically non-existent.
>
> I wonder if there's a benefit to removing a small potential footgun from
> the language? I can't really see any benefit to _keeping_ it (unless it
> turns out my analysis is wrong, and it's actually wildly popular).
>
> Best wishes,
>
> Matt
Hi Matt,
As a user-land developer, I would be very much against changing this.
I’m sure it’s probably not a particularly common way to format code, but the ability to chain
method calls, starting from a static call and have it formatted with one method call per-line is
quite useful IMO, eg:
```
MyModelClass
::find(1)
->where(‘foo’, time(), ‘>’)
->where(‘bar’, null, ‘is not’)
->readAll();
```
But more generically - I can’t see why you’d think that this one particular instance of extra
whitespace being insignificant is a problem, when extra whitespace is not significant anywhere?
In other worse, can you explain why you think it’s a problem that whitespace is not significant in
static method calls, but it’s not a problem everywhere else where it’s not significant?
The two following examples are the extremes of extra whitespace vs minimal whitespace, and your
suggestion would introduce an arbitrary inconsistency for one specific case.
```
<?php namespace Foo; class Bar implements \JsonSerializable { public function jsonSerialize():
mixed {return self::class;} public static function create(): static { return new static(); }} $f =
Bar::create(); echo \json_encode($f); var_dump($f); ?>
```
```
<?php
namespace
Foo
;
class
Bar
implements
\JsonSerializable
{
public
function
jsonSerialize
(
)
:
mixed
{
return
self
::
class
;
}
public
static
function
create
(
)
:
static
{
return
new
static
(
)
;
}
}
$f
=
Bar
::
create
(
)
;
echo
\json_encode
(
$f
)
;
var_dump
(
$f
)
;
?>
```
Cheers
Stephen