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); }
Output for git.master
string(315) "O:3:"Foo":5:{s:4:"date";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2024-02-08 08:41:10.007219";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:6:"*foo";s:11:"Foo bar baz";s:8:"Foobar";i:123456789;s:3:"tbl";a:4:{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:"baz";}s:8:"*color";E:12:"Color:Yellow";}" Reducing by potentially unnecessary chars... By removing double-quote serialized output shrinks by 10.53% string(285) "O:3:Foo:5:{s:4:date;O:17:DateTimeImmutable:3:{s:4:date;s:26:2024-02-08 08:41:10.007219;s:13:timezone_type;i:3;s:8:timezone;s:16:Europe/Amsterdam;}s:6:*foo;s:11:Foo bar baz;s:8:Foobar;i:123456789;s:3:tbl;a:4:{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:baz;}s:8:*color;E:12:Color:Yellow;}" By removing previous and array leading double-colon and trailing semi-colon serialized output shrinks by 12.90% string(279) "O:3:Foo:5{s:4:date;O:17:DateTimeImmutable:3{s:4:date;s:26:2024-02-08 08:41:10.007219;s:13:timezone_type;i:3;s:8:timezone;s:16:Europe/Amsterdam}s:6:*foo;s:11:Foo bar baz;s:8:Foobar;i:123456789;s:3:tbl;a:4{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:baz}s:8:*color;E:12:Color:Yellow}" By removing previous and leading double-colon of sized types serialized output shrinks by 19.77% string(263) "O3:Foo:5{s4:date;O17:DateTimeImmutable:3{s4:date;s26:2024-02-08 08:41:10.007219;s13:timezone_type;i:3;s8:timezone;s16:Europe/Amsterdam}s6:*foo;s11:Foo bar baz;s8:Foobar;i:123456789;s3:tbl;a4{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s3:baz}s8:*color;E12:Color:Yellow}" By aggresive removing previous and some double-colons serialized output shrinks by 24.02% string(254) "O3:Foo:5{s4:date;O17:DateTimeImmutable:3{s4:date;s26:2024-02-08 08:41:10.007219;s13:timezone_type;i3;s8:timezone;s16:Europe/Amsterdam}s6:*foo;s11:Foo bar baz;s8:Foobar;i123456789;s3:tbl;a4{i0;i123;i1;b1;i2;d1.1;i3;s3:baz}s8:*color;E12:Color:Yellow}"
Output for git.master_jit
string(315) "O:3:"Foo":5:{s:4:"date";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2024-02-08 08:41:10.007261";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:6:"*foo";s:11:"Foo bar baz";s:8:"Foobar";i:123456789;s:3:"tbl";a:4:{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:"baz";}s:8:"*color";E:12:"Color:Yellow";}" Reducing by potentially unnecessary chars... By removing double-quote serialized output shrinks by 10.53% string(285) "O:3:Foo:5:{s:4:date;O:17:DateTimeImmutable:3:{s:4:date;s:26:2024-02-08 08:41:10.007261;s:13:timezone_type;i:3;s:8:timezone;s:16:Europe/Amsterdam;}s:6:*foo;s:11:Foo bar baz;s:8:Foobar;i:123456789;s:3:tbl;a:4:{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:baz;}s:8:*color;E:12:Color:Yellow;}" By removing previous and array leading double-colon and trailing semi-colon serialized output shrinks by 12.90% string(279) "O:3:Foo:5{s:4:date;O:17:DateTimeImmutable:3{s:4:date;s:26:2024-02-08 08:41:10.007261;s:13:timezone_type;i:3;s:8:timezone;s:16:Europe/Amsterdam}s:6:*foo;s:11:Foo bar baz;s:8:Foobar;i:123456789;s:3:tbl;a:4{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:baz}s:8:*color;E:12:Color:Yellow}" By removing previous and leading double-colon of sized types serialized output shrinks by 19.77% string(263) "O3:Foo:5{s4:date;O17:DateTimeImmutable:3{s4:date;s26:2024-02-08 08:41:10.007261;s13:timezone_type;i:3;s8:timezone;s16:Europe/Amsterdam}s6:*foo;s11:Foo bar baz;s8:Foobar;i:123456789;s3:tbl;a4{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s3:baz}s8:*color;E12:Color:Yellow}" By aggresive removing previous and some double-colons serialized output shrinks by 24.02% string(254) "O3:Foo:5{s4:date;O17:DateTimeImmutable:3{s4:date;s26:2024-02-08 08:41:10.007261;s13:timezone_type;i3;s8:timezone;s16:Europe/Amsterdam}s6:*foo;s11:Foo bar baz;s8:Foobar;i123456789;s3:tbl;a4{i0;i123;i1;b1;i2;d1.1;i3;s3:baz}s8:*color;E12:Color:Yellow}"
Output for rfc.property-hooks
string(315) "O:3:"Foo":5:{s:4:"date";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2024-02-08 08:41:10.006622";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:6:"*foo";s:11:"Foo bar baz";s:8:"Foobar";i:123456789;s:3:"tbl";a:4:{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:"baz";}s:8:"*color";E:12:"Color:Yellow";}" Reducing by potentially unnecessary chars... By removing double-quote serialized output shrinks by 10.53% string(285) "O:3:Foo:5:{s:4:date;O:17:DateTimeImmutable:3:{s:4:date;s:26:2024-02-08 08:41:10.006622;s:13:timezone_type;i:3;s:8:timezone;s:16:Europe/Amsterdam;}s:6:*foo;s:11:Foo bar baz;s:8:Foobar;i:123456789;s:3:tbl;a:4:{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:baz;}s:8:*color;E:12:Color:Yellow;}" By removing previous and array leading double-colon and trailing semi-colon serialized output shrinks by 12.90% string(279) "O:3:Foo:5{s:4:date;O:17:DateTimeImmutable:3{s:4:date;s:26:2024-02-08 08:41:10.006622;s:13:timezone_type;i:3;s:8:timezone;s:16:Europe/Amsterdam}s:6:*foo;s:11:Foo bar baz;s:8:Foobar;i:123456789;s:3:tbl;a:4{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:baz}s:8:*color;E:12:Color:Yellow}" By removing previous and leading double-colon of sized types serialized output shrinks by 19.77% string(263) "O3:Foo:5{s4:date;O17:DateTimeImmutable:3{s4:date;s26:2024-02-08 08:41:10.006622;s13:timezone_type;i:3;s8:timezone;s16:Europe/Amsterdam}s6:*foo;s11:Foo bar baz;s8:Foobar;i:123456789;s3:tbl;a4{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s3:baz}s8:*color;E12:Color:Yellow}" By aggresive removing previous and some double-colons serialized output shrinks by 24.02% string(254) "O3:Foo:5{s4:date;O17:DateTimeImmutable:3{s4:date;s26:2024-02-08 08:41:10.006622;s13:timezone_type;i3;s8:timezone;s16:Europe/Amsterdam}s6:*foo;s11:Foo bar baz;s8:Foobar;i123456789;s3:tbl;a4{i0;i123;i1;b1;i2;d1.1;i3;s3:baz}s8:*color;E12:Color:Yellow}"

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:
60.64 ms | 417 KiB | 5 Q