3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class StringObject { protected string $string; public function __tostring(): string { return $this->string; } } class StringObjectException extends Exception {} class CountableString extends StringObject { private int $lettersCount; public function __construct(string $string) { $this->string = $string; $this->lettersCount = mb_strlen($string); } public function countLetters(): int { return $this->lettersCount; } } class EmptyStringException extends Exception {}; class NotEmptyString extends StringObject { public function __construct(string $string) { if ('' === $string) { throw new EmptyStringException('Expected not empty string.'); } $this->string = $string; } } class TooLongStringException extends Exception {}; class TenLettersString extends StringObject { private const MAX_LETTERS_COUNT = 10; public function __construct(CountableString $string) { if (self::MAX_LETTERS_COUNT < $string->countLetters()) { throw new TooLongStringException( sprintf('Expected string not longer then: "%d letters" got: "%s"', self::MAX_LETTERS_COUNT, $string ) ); } $this->string = $string; } } $countableString = new CountableString('Тестовая строка'); $notEmptyString = new NotEmptyString($countableString); echo $countableString->countLetters() . PHP_EOL; echo $countableString . PHP_EOL; $tenLetterLongString = new TenLettersString($countableString);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
15 Тестовая строка Fatal error: Uncaught TooLongStringException: Expected string not longer then: "10 letters" got: "Тестовая строка" in /in/XhAE2:45 Stack trace: #0 /in/XhAE2(63): TenLettersString->__construct(Object(CountableString)) #1 {main} thrown in /in/XhAE2 on line 45
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
105.57 ms | 407 KiB | 5 Q