Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 3, 2023
1 parent 4eda8ba commit cc3cf4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Schema/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ public static function getCastStrategy(string $type): \Closure
};
} elseif (method_exists($type, '__construct')) {
return static function ($value) use ($type) {
if (PHP_VERSION_ID < 80000 && is_array($value)) {
throw new Nette\NotSupportedException("Creating $type objects is supported since PHP 8.0");
}
return is_array($value)
? new ($type)(...$value)
: new ($type)($value);
? new $type(...$value)
: new $type($value);
};
} else {
return static function ($value) use ($type) {
Expand Down
4 changes: 4 additions & 0 deletions tests/Schema/Expect.castTo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ test('simple object', function () {


test('object with constructor', function () {
if (PHP_VERSION_ID < 80000) {
return;
}

class Foo2
{
private int $a;
Expand Down

0 comments on commit cc3cf4f

Please sign in to comment.