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 git.master, git.master_jit
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( ))"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
29.86 ms | 408 KiB | 5 Q