Re: What's new in 8.2: DNF types

From: Date: Thu, 08 Dec 2022 14:40:03 +0000
Subject: Re: What's new in 8.2: DNF types
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-119100@lists.php.net to get a copy of this message
On Thu, Dec 8, 2022 at 1:39 PM Thomas Gutbier <thomas.gutbier@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; > } > } > > 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

« previous php.internals (#119100) next »