3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Foo implements \Stringable { private function __construct(public readonly string $value) { } public static function fromString(string $string): self { return new self($string); } /** * {@inheritdoc} */ public function __toString(): string { return $this->value; } } $options = [ Foo::fromString('c'), Foo::fromString('b'), Foo::fromString('a'), Foo::fromString('ccc'), Foo::fromString('bcc'), ]; uasort($options, strnatcasecmp(...)); var_export($options);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
array ( 2 => \Foo::__set_state(array( 'value' => 'a', )), 1 => \Foo::__set_state(array( 'value' => 'b', )), 4 => \Foo::__set_state(array( 'value' => 'bcc', )), 0 => \Foo::__set_state(array( 'value' => 'c', )), 3 => \Foo::__set_state(array( 'value' => 'ccc', )), )
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.
Output for 8.1.0 - 8.1.33
array ( 2 => Foo::__set_state(array( 'value' => 'a', )), 1 => Foo::__set_state(array( 'value' => 'b', )), 4 => Foo::__set_state(array( 'value' => 'bcc', )), 0 => Foo::__set_state(array( 'value' => 'c', )), 3 => Foo::__set_state(array( 'value' => 'ccc', )), )

preferences:
77.39 ms | 409 KiB | 5 Q