PHP 8.3: class_alias() supports aliasing built-in PHP classes

Version8.3
TypeNew Feature

The class_alias PHP function creates an alias for a provided class. The aliased class behaves exactly the same as the original class.

Prior to PHP 8.3, attempting to alias a built-in PHP class resulted in a ValueError exception:

// Not allowed in PHP < 8.3
class_alias('stdClass', 'MyNewClass'); 
class_alias('Traversable', 'NewTraversableInterface');
ValueError: class_alias(): Argument #1 ($class) must be a user-defined class name, internal class name given

Since PHP 8.3 and later, it is possible to alias internal classes and interfaces. The snippet above is allowed, and class_alias correctly aliases internal classes as well:

// Allowed in PHP >= 8.3
class_alias('stdClass', 'MyNewClass'); 
class_alias('Traversable', 'NewTraversableInterface');

The class_alias() function accepts a bool $autoload = true as the third parameter. This parameter has no effect on built-in classes because they do not need to be autoloaded. However, despite having no meaningful effect, passing a value to this parameter is still allowed and does not trigger any warnings or errors.