While using Nette/Schema I found little discomfort when using PHP 8 features - specifically Constructor property promotion.
Let's imagine following class:
class Foo
{
public function __construct(
public int $a,
public int $b,
) {
}
}
Casting to this class will result in ArgumentCountError because Schema is instantiating the class using new keyword.
This can be solved with instantiating the class using Reflection and it's newInstanceWithoutConstructor method.
I solved this with adding second argument to castTo: castTo(string $type, bool $usingReflection = false): self - default behavior is not changed so it's not causing BC break.
While using Nette/Schema I found little discomfort when using PHP 8 features - specifically Constructor property promotion.
Let's imagine following class:
Casting to this class will result in ArgumentCountError because Schema is instantiating the class using
new
keyword. This can be solved with instantiating the class using Reflection and it'snewInstanceWithoutConstructor
method.I solved this with adding second argument to castTo:
castTo(string $type, bool $usingReflection = false): self
- default behavior is not changed so it's not causing BC break.Tests included and passing.