On Thu, Dec 8, 2022 at 1:39 PM Thomas Gutbier
<[email protected]> 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;
> }
> }
>
> Best regards
> Thomas Gutbier
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php