3v4l.org

run code in 500+ PHP versions simultaneously
<?php // declare(strict_types=1); function typeJuggleToInt(int $value): int { return $value; } function typeJuggleToString(string $value): string { return $value; } function isStrictTypesActive(): bool { $check = function (string $value): void { }; try { // Under strict_types a float will not be type-juggled to a string. $check(123.45); return false; } catch (\Throwable $ex) { return true; } } trait changed_tryFrom { private static function is_backing_type_int(): bool { $backingtype = (new \ReflectionEnum(self::class))->getBackingType()->getName(); return 'int' === $backingtype; } private static function is_backing_type_string(): bool { $backingtype = (new \ReflectionEnum(self::class))->getBackingType()->getName(); return 'string' === $backingtype; } public static function changed_tryFrom(mixed $value): self|null { if ($value instanceof self) { // nothing to do, already a valid "self". return $value; } elseif (is_int($value)) { if (isStrictTypesActive()) { if (!self::is_backing_type_int()) { // prevent Argument #1 ($value) must be of type int return null; } } // take the normal int path return self::tryFrom($value); } elseif (is_string($value)) { if (isStrictTypesActive()) { if (!self::is_backing_type_string()) { // prevent Argument #1 ($value) must be of type string return null; } } // take the normal string path return self::tryFrom($value); } elseif (null === $value) { // A backed enum of type int or type string can never contain the null value. // Prevent warning "Passing null to parameter #1 ($value) of type string|int is deprecated". return null; } else { if (!isStrictTypesActive()) { // no strict_types statement --> type juggling is active. // // BC type-juggling // type juggling: Coercive typing with union types // 1. int, 2. string try { return self::tryFrom(typeJuggleToInt($value)); } catch (\Throwable $ex) { // can't be type juggled to int } try { return self::tryFrom(typeJuggleToString($value)); } catch (\Throwable $ex) { // can't be type juggled to string } } // invalid type return null; } // never reached } } enum SuitAsInt: int { use \changed_tryFrom; case Clubs = 1; case Diamonds = 2; case Hearts = 3; case Spades = 4; } enum SuitAsString: string { use \changed_tryFrom; case Clubs = '1'; case Diamonds = '2'; case Hearts = '3'; case Spades = '4'; } $testcases = [ new \DateTimeImmutable(), null, 4, 4.0, '4', \SuitAsInt::Spades, \SuitAsString::Spades, ]; foreach ($testcases as $testcase) { echo '----------------------------------------'."\n"; echo '--------------[ TESTCASE ]--------------'."\n"; echo '----------------------------------------'."\n"; var_dump($testcase); echo "\n"; echo '------- [ INT backed enum ] -------'."\n"; echo '--- SuitAsInt::tryFrom()'."\n"; try { $value = \SuitAsInt::tryFrom($testcase); if (null !== $value) { echo 'Value is '.$value->name.' with value '.$value->value.'.'."\n"; } else { echo 'Value is NULL.'."\n"; } } catch (\Throwable $exception) { echo $exception::class, ': ', $exception->getMessage(), "\n"; } echo '--- SuitAsInt::changed_tryFrom() [CHANGED]'."\n"; try { $value = \SuitAsInt::changed_tryFrom($testcase); if (null !== $value) { echo 'Value is '.$value->name.' with value '.$value->value.'.'."\n"; } else { echo 'Value is NULL.'."\n"; } } catch (\Throwable $exception) { echo $exception::class, ': ', $exception->getMessage(), "\n"; } echo "\n"; echo '------- [ STRING backed enum ] -------'."\n"; echo '--- SuitAsString::tryFrom()'."\n"; try { $value = \SuitAsString::tryFrom($testcase); if (null !== $value) { echo 'Value is '.$value->name.' with value '.$value->value.'.'."\n"; } else { echo 'Value is NULL.'."\n"; } } catch (\Throwable $exception) { echo $exception::class, ': ', $exception->getMessage(), "\n"; } echo '--- SuitAsString::changed_tryFrom() [CHANGED]'."\n"; try { $value = \SuitAsString::changed_tryFrom($testcase); if (null !== $value) { echo 'Value is '.$value->name.' with value '.$value->value.'.'."\n"; } else { echo 'Value is NULL.'."\n"; } } catch (\Throwable $exception) { echo $exception::class, ': ', $exception->getMessage(), "\n"; } echo "\n"; echo "\n"; }
Output for 8.5.9
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.008462" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.5.11
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.004323" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.5.10
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.007508" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.4.26
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.006096" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.4.25
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.010134" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.4.9
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.005325" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.3.18
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.004016" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.3.5
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.006179" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.2.34
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.005092" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.
Output for 8.3.35
---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2026-08-31 17:50:05.005628" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, DateTimeImmutable given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, DateTimeImmutable given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- NULL ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Deprecated: SuitAsInt::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 145 Value is NULL. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Deprecated: SuitAsString::tryFrom(): Passing null to parameter #1 ($value) of type string|int is deprecated in /in/h9cNW on line 172 Value is NULL. --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- int(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- float(4) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- string(1) "4" ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() Value is Spades with value 4. --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() Value is Spades with value 4. --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsInt::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsInt given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is Spades with value 4. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsInt given --- SuitAsString::changed_tryFrom() [CHANGED] Value is NULL. ---------------------------------------- --------------[ TESTCASE ]-------------- ---------------------------------------- enum(SuitAsString::Spades) ------- [ INT backed enum ] ------- --- SuitAsInt::tryFrom() TypeError: SuitAsInt::tryFrom(): Argument #1 ($value) must be of type int, SuitAsString given --- SuitAsInt::changed_tryFrom() [CHANGED] Value is NULL. ------- [ STRING backed enum ] ------- --- SuitAsString::tryFrom() TypeError: SuitAsString::tryFrom(): Argument #1 ($value) must be of type string|int, SuitAsString given --- SuitAsString::changed_tryFrom() [CHANGED] Value is Spades with value 4.

preferences:
38.18 ms | 1212 KiB | 15 Q