3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Entity { class File { private $foo = 'top'; } class FileInbox { public $file; public function setFile(File $file) { $this->file = $file; } } } namespace Entity\FileInbox { class File { private $foo = 'nested'; } } namespace Test { use Entity\FileInbox; use Entity\FileInbox\File; $fileInbox = new FileInbox(); $fileInbox->setFile(new File()); var_dump($fileInbox->file->foo); }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: Entity\FileInbox::setFile(): Argument #1 ($file) must be of type Entity\File, Entity\FileInbox\File given, called in /in/iLbni on line 28 and defined in /in/iLbni:11 Stack trace: #0 /in/iLbni(28): Entity\FileInbox->setFile(Object(Entity\FileInbox\File)) #1 {main} thrown in /in/iLbni on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 1 passed to Entity\FileInbox::setFile() must be an instance of Entity\File, instance of Entity\FileInbox\File given, called in /in/iLbni on line 28 and defined in /in/iLbni:11 Stack trace: #0 /in/iLbni(28): Entity\FileInbox->setFile(Object(Entity\FileInbox\File)) #1 {main} thrown in /in/iLbni on line 11
Process exited with code 255.
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Catchable fatal error: Argument 1 passed to Entity\FileInbox::setFile() must be an instance of Entity\File, instance of Entity\FileInbox\File given, called in /in/iLbni on line 28 and defined in /in/iLbni on line 11
Process exited with code 255.

preferences:
193.7 ms | 402 KiB | 270 Q