[php-src] Issue #8941: Type intersection not working with traits

From: Date: Wed, 06 Jul 2022 18:26:06 +0000
Subject: [php-src] Issue #8941: Type intersection not working with traits
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241873@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8941 Author: FlameStorm ### Description Greetings, PHP-dev team! I found type intersection works strange / not working with traits. The following code: ```php <?php class Entity {} trait Foobarable {} class TestEntity extends Entity { use Foobarable; } function test(Entity&Foobarable $obj) { echo "PHP is awesome!"; } $obj = new TestEntity(); test($obj); ``` Resulted in this output: ``` Fatal error: Uncaught TypeError: test(): Argument #1 ($obj) must be of type Entity&Foobarable, TestEntity given, called in /var/www/public/test.php on line 12 and defined in /var/www/public/test.php:7 Stack trace: #0 /var/www/public/test.php(12): test(Object(TestEntity)) #1 {main} thrown in /var/www/public/test.php on line 7 ``` (line 7 is - function test(Entity&Foobarable $obj) { ) But I expected this output instead: ``` PHP is awesome! ``` I sure it must work, but it isnt... It looks like a bug, so I wrote to you! <3 Thanks a lot! ### PHP Version PHP 8.1.7 ### Operating System _No response_

« previous php.bugs (#241873) next »