nicolas-grekas wrote on the PR:
> ?X&Y cannot be confused with

It confused me. A compiler might understand it, but as a human I have
trouble understanding it.

Trowski wrote:
> The syntax should be either ?(X&Y) or (X&Y)|null

Non-ambiguous syntax is much better than ambiguous syntax.

On Mon, 19 Jul 2021 at 15:26, Nicolas Grekas <nicolas.gre...@gmail.com> wrote:
> I don't know the future, and nobody does.

Maybe not, but we can look at the past and make predictions.

Allowing null when then parameter type does not include null is
supported in function parameters for legacy reasons:

```
class Bar{}
function foo(Bar $bar = null) {} // parameter has implicit nullability.
```

But it was deliberately excluded from typed-properties:

```
class Bar{}

class Foo
{
    private Bar $bar = null;
}

PHP Fatal error:  Default value for property of type Bar may not be
null. Use the nullable type ?Bar to allow null default value in ....
```

Instead, you are required to be explicit on the type declaration:

class Foo
{
    private ?Bar $bar = null;
}


Prediction number 1: At some point implicit type nullability of
function parameters will be deprecated. People should consider
changing any code they have from implicit declaration to explicit.
e.g.
change:

function foo(Bar $bar = null) {}

to

function foo(?Bar $bar) {}

Prediction number 2: Having a null type in the language will happen
before PHP 9, which will enable people to have many bike-shedding
discussions over ?Bar vs Bar|null.

But this discussion is moot for 8.1.

This limitation might make intersection types not be considered usable
by some projects, but the feature freeze is today.

cheers
Dan
Ack

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to