Skip to content

v6.4.2

Latest
Compare
Choose a tag to compare
@sagittaracc sagittaracc released this 22 Apr 13:46
· 2 commits to main since this release
  • Add generic support for method parameters
use Sagittaracc\PhpPythonDecorator\Decorator;
use Sagittaracc\PhpPythonDecorator\modules\generics\aliases\T;
use Sagittaracc\PhpPythonDecorator\modules\validation\core\validators\ArrayOf;

#[T]
class Box
{
    use Decorator;

    #[ArrayOf(T::class)]
    public $items;

    public function addItem(#[T] $item)
    {
        $this->items[] = $item;
    }
}

$box = new Box();
$box(Pen::class); // new Box<Pen>();
call_decorator_func_array([$box, 'addItem'], [new Pencil]); // throws a GenericError