3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Secured { public function __construct( private readonly \SensitiveParameterValue $content ) { } public static function fromString( #[\SensitiveParameter] string $value, ) { return new self(new \SensitiveParameterValue($value)); } public function __toString(): string { return '**SECRET**'; } public function __debugInfo(): ?array { return [ 'content' => '**SECRET**' ]; } public function __serialize(): array { return []; } public function __unserialize(array $data): void { throw new \RuntimeException('The ' . __CLASS__ . ' class cannot be unserialized.'); } } function t(string $n, callable $c) { echo "$n ::::::::::::::::::::::::::::::::::::::::" . PHP_EOL; try { $c(); } catch (Throwable $e) { echo $e->getMessage() . PHP_EOL; } echo PHP_EOL; } function test(Secured|SensitiveParameterValue $secured) { echo 'Test ' .get_class($secured). ' _____________________________________________________________' . PHP_EOL; t('var_dump', fn () => var_dump($secured)); t('serialize', fn () => var_dump(serialize($secured))); t('print_r', fn () => print_r($secured)); t('casting', fn () => var_dump((string) $secured)); t('var_export', fn () => var_dump(var_export($secured, true))); } test(Secured::fromString('Lorem ipsum dolor')); test(new \SensitiveParameterValue('Lorem ipsum dolor'));
Output for 8.3.5 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Test Secured _____________________________________________________________ var_dump :::::::::::::::::::::::::::::::::::::::: object(Secured)#1 (1) { ["content"]=> string(10) "**SECRET**" } serialize :::::::::::::::::::::::::::::::::::::::: string(18) "O:7:"Secured":0:{}" print_r :::::::::::::::::::::::::::::::::::::::: Secured Object ( [content] => **SECRET** ) casting :::::::::::::::::::::::::::::::::::::::: string(10) "**SECRET**" var_export :::::::::::::::::::::::::::::::::::::::: string(101) "\Secured::__set_state(array( 'content' => \SensitiveParameterValue::__set_state(array( )), ))" Test SensitiveParameterValue _____________________________________________________________ var_dump :::::::::::::::::::::::::::::::::::::::: object(SensitiveParameterValue)#1 (0) { } serialize :::::::::::::::::::::::::::::::::::::::: Serialization of 'SensitiveParameterValue' is not allowed print_r :::::::::::::::::::::::::::::::::::::::: SensitiveParameterValue Object ( ) casting :::::::::::::::::::::::::::::::::::::::: Object of class SensitiveParameterValue could not be converted to string var_export :::::::::::::::::::::::::::::::::::::::: string(47) "\SensitiveParameterValue::__set_state(array( ))"
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.2.20 - 8.2.29
Test Secured _____________________________________________________________ var_dump :::::::::::::::::::::::::::::::::::::::: object(Secured)#1 (1) { ["content"]=> string(10) "**SECRET**" } serialize :::::::::::::::::::::::::::::::::::::::: string(18) "O:7:"Secured":0:{}" print_r :::::::::::::::::::::::::::::::::::::::: Secured Object ( [content] => **SECRET** ) casting :::::::::::::::::::::::::::::::::::::::: string(10) "**SECRET**" var_export :::::::::::::::::::::::::::::::::::::::: string(101) "\Secured::__set_state(array( 'content' => \SensitiveParameterValue::__set_state(array( )), ))" Test SensitiveParameterValue _____________________________________________________________ var_dump :::::::::::::::::::::::::::::::::::::::: object(SensitiveParameterValue)#1 (0) { } serialize :::::::::::::::::::::::::::::::::::::::: Serialization of 'SensitiveParameterValue' is not allowed print_r :::::::::::::::::::::::::::::::::::::::: SensitiveParameterValue Object casting :::::::::::::::::::::::::::::::::::::::: Object of class SensitiveParameterValue could not be converted to string var_export :::::::::::::::::::::::::::::::::::::::: string(47) "\SensitiveParameterValue::__set_state(array( ))"
Output for 8.1.30 - 8.1.33
Fatal error: Uncaught Error: Class "SensitiveParameterValue" not found in /in/IPXe0:16 Stack trace: #0 /in/IPXe0(67): Secured::fromString('Lorem ipsum dol...') #1 {main} thrown in /in/IPXe0 on line 16
Process exited with code 255.

preferences:
72.12 ms | 412 KiB | 5 Q