On 08.12.2022 at 15:40, Robert Landers wrote:

> On Thu, Dec 8, 2022 at 1:39 PM Thomas Gutbier
> <thomas.gutb...@anthrotec.de> wrote:
>
>> I think in this example the check for null can be removed.
>> The feature is so much more useful than presented here.
>>
>> (https://www.php.net/releases/8.2/en.php#dnf_types)
>>
>>     class Foo {
>>         public function bar((A&B)|null $entity) {
>> -          if ($entity === null) {
>> -              return null;
>> -          }
>>
>>             return $entity;
>>         }
>>     }

I think accordingly there should only be a single if-statement in the
PHP < 8.2 code sample.

> I'd also like to point out that this doesn't cause a fatal error, at
> least in the latest RC (I haven't tried the official release yet).
>
> trait Foo
> {
>     public const CONSTANT = 1;
>
>     public function bar(): int
>     {
>         return self::CONSTANT; // Fatal error
>     }
> }
>
> class Bar
> {
>     use Foo;
> }
>
> var_dump(Bar::CONSTANT); // 1
> var_dump((new Bar)->bar()); // 1

Indeed, this example is borked.  There is no fatal error at this place
prior to PHP 8.2.0 either; rather, line 5 raises a fatal error ("Traits
cannot have constants").

--
Christoph M. Becker

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

Reply via email to