Re: [RFC] Type Aliases
| From: | Paul M. Jones | Date: | Wed, 03 Dec 2025 21:27:55 +0000 |
| Subject: | Re: [RFC] Type Aliases | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129532@lists.php.net to get a copy of this message | ||
Hey Rob & all,
One objection, one question.
The objection is to
include types 'types.php'. You've clarified why
types cannot be autoloaded (thanks again!) and so this is a way to let the compiler know where the
types are. But I have to say I've spent a huge part of my career removing include/require when
refactoring legacy code, and introducing it here causes me great heartache.
The question is a little more complicated, and also involves autoloading. Given a class Number that
can be autoloaded ...
namespace Foo;
class Number { /* ... */ }
... and *another* class in the same namespace, that creates a "number" type alias...
namespace Foo;
use type int|float as Number;
class Bar { public function add(Number $a, Number $b) : Number { /* ... */ }
... which one "wins" -- the runtime autoloaded class, or the compile-time type alias?
(Apologies if this is covered in the RFC and I missed it.)
-- pmj