3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); enum Color: string { case Yellow = 'yw'; } class Foo { public function __construct( public DateTimeImmutable $date, protected string $foo, private int $bar, public array $tbl = [123, true, 1.1, 'baz'], protected Color $color = Color::Yellow, ) {} } $current = serialize(new Foo(new DateTimeImmutable('now'), "Foo bar\nbaz", 123456789)); var_dump($current); echo "\nReducing by potentially unnecessary chars...\n"; $reductions = []; $replacements = ['"' => '']; $reductions['removing double-quote'] = strtr($current, $replacements); $replacements[';}'] = '}'; $replacements[':{'] = '{'; $reductions['removing previous and array leading double-colon and trailing semi-colon'] = strtr($current, $replacements); $replacements['O:'] = 'O'; $replacements['a:'] = 'a'; $replacements['s:'] = 's'; $replacements['E:'] = 'E'; $reductions['removing previous and leading double-colon of sized types'] = strtr($current, $replacements); $replacements['i:'] = 'i'; $replacements['d:'] = 'd'; $replacements['b:'] = 'b'; $reductions['aggresive removing previous and some double-colons'] = strtr($current, $replacements); foreach ($reductions as $name => $serialized) { printf("\nBy {$name} serialized output shrinks by %0.2f%%\n", (strlen($current) - strlen($serialized)) / strlen($serialized) * 100); var_dump($serialized); }

preferences:
25.57 ms | 407 KiB | 5 Q