3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); 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'), ]; var_dump(strnatcasecmp($options[1], $options[2])); uasort($options, 'strnatcasecmp'); var_export($options);
Output for 8.3.5 - 8.3.30, 8.4.9
Fatal error: Uncaught TypeError: strnatcasecmp(): Argument #1 ($string1) must be of type string, Foo given in /in/slZeW:29 Stack trace: #0 /in/slZeW(29): strnatcasecmp(Object(Foo), Object(Foo)) #1 {main} thrown in /in/slZeW on line 29
Process exited with code 255.

preferences:
41.53 ms | 502 KiB | 4 Q