XP Core dependencies
Opened this issue · 2 comments
thekid commented
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 augmentation- XP meta information for extended types such as
array<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- hard-wired
.class.php
file extension -see #159
thekid commented
Casting
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.
thekid commented
Casting could be made obsolete if something like the as
-assertions were to be added to PHP: https://externals.io/message/122687