Open thekid opened 2 years ago
XP Compiler supports casting to any type, including value types and those not present in the PHP type system (but supported by tools like PHPDoc, PHPStan and others), like array<string>
:
// Syntax
$input= (array<string>)$parameters->named('list');
// Rewritten to use the cast function from XP Core
$input= cast($parameters->named('list'), 'string[]');
Extracting this functionality would create quite some overhead in the compiler and result in lots of duplicated code being generated.
Casting could be made obsolete if something like the as
-assertions were to be added to PHP: https://externals.io/message/122687
This ticket tracks the dependencies on XP core:
cast()
for casting anything other than string, int, float, bool, array and object (and nullable versions of these, see #131)typeof()
in the VirtualPropertyTypes augmentationarray<int>
, as seen in this failing test if XpMeta is removed:util.Objects::stringOf()
inside RewriteEnums used in PHP < 8.1lang.VirtualProperty
for being able to set readonly properties via reflectionis()
in the VirtualPropertyTypes augmentation.class.php
file extension -see #159