3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function profile($c, $n = 1000) { $m = 'microtime'; for ($i = $n * is_callable($c), $t = 0;$i--;$w = $m(1), $c(), $t+= ($m(1) - $w) / $n); return $t; } class Foo { protected $foo; protected $bar; protected $baz; } class FooSelfHydratingProxy extends Foo { /** zero-argument constructor since this is just a helper class for hydration */ public function __construct() { } /** * the `Foo` typehint is not part of the interface - here only for the sake of readability/clearness */ public function hydrate($data, Foo $object) { $object->foo = $data['foo']; $object->bar = $data['bar']; $object->baz = $data['baz']; } /** * the `Foo` typehint is not part of the interface - here only for the sake of readability/clearness */ public function extract(Foo $object) { return array('foo' => $object->foo, 'bar' => $object->bar, 'baz' => $object->baz); } } // data $data = array('foo' => 1, 'bar' => 2, 'baz' => 3); // lastguest function dehydrate($obj){ $class = get_class($obj); $exp = var_export($obj,1); return eval('return '.substr($exp,strpos($exp,'(')+1,-1).';'); } function static_hydrate($class,$dry=null){ static $hydrators = array(); $h = '_Hydrator__'.$class; if (empty($hydrators[$class])) { eval("class $h extends $class { static function __hydrate(\$a) { \$o = new $class(); foreach (\$a as \$n=>\$v) \$o->\$n=\$v; return \$o; } } function hydrate_$class(\$o){return $h::__hydrate(\$o);}" ); $hydrators[$class] = true; } return $dry?$h::__hydrate($dry):new $h; } function hydrate($class,$dry=null){ static $hydrators = array(); $h = '_Hydrator__'.$class; if (empty($hydrators[$class])) { eval("class $h extends $class { static function __hydrate(\$a) { \$o = new $class(); foreach (\$a as \$n=>\$v) \$o->\$n=\$v; return \$o; } } function hydrate_$class(\$o){return $h::__hydrate(\$o);}" ); $hydrators[$class] = true; } return $dry?$h::__hydrate($dry):new $h; } $hydrator = new FooSelfHydratingProxy(); echo 'Ocramius: ',profile(function() use ($data,$hydrator) { $hydrated = new Foo(); $hydrator->hydrate($data, $hydrated); })*1E6,PHP_EOL; $hydr = static_hydrate('Foo'); echo 'Lastguest: ',profile(function() use ($data) { hydrate_Foo($data); })*1E6,PHP_EOL; $hydr = static_hydrate('Foo'); echo 'Lastguest: ',profile(function() use ($data,$hydr) { $hydr->__hydrate($data); })*1E6,PHP_EOL; $foo = hydrate_Foo($data); $foo_s = serialize($foo); echo 'Lastguest: ',profile(function() use ($data,$foo_s) { unserialize($foo_s); })*1E6,PHP_EOL;
Output for 7.2.0
Ocramius: 0.47659873962402 Lastguest: 0.76198577880859 Lastguest: 0.76603889465332 Lastguest: 1.8038749694824
Output for 7.1.7
Ocramius: 0.32877922058105 Lastguest: 0.36764144897461 Lastguest: 0.38719177246094 Lastguest: 0.81610679626465
Output for 7.1.6
Ocramius: 0.35858154296875 Lastguest: 0.39243698120117 Lastguest: 0.36859512329102 Lastguest: 0.81849098205566
Output for 7.1.5
Ocramius: 0.69880485534668 Lastguest: 0.84567070007324 Lastguest: 0.82063674926758 Lastguest: 1.9509792327881
Output for 7.1.0
Ocramius: 0.64206123352051 Lastguest: 0.68593025207519 Lastguest: 0.70023536682129 Lastguest: 1.4786720275879
Output for 7.0.20
Ocramius: 0.37503242492676 Lastguest: 0.41532516479492 Lastguest: 0.42033195495605 Lastguest: 0.87785720825195
Output for 7.0.14
Ocramius: 0.73742866516113 Lastguest: 0.73885917663574 Lastguest: 0.73194503784179 Lastguest: 1.4858245849609
Output for 7.0.6
Ocramius: 0.51355361938476 Lastguest: 0.63252449035644 Lastguest: 0.56910514831543 Lastguest: 1.2831687927246
Output for 7.0.5
Ocramius: 0.52332878112793 Lastguest: 0.65040588378906 Lastguest: 0.60963630676269 Lastguest: 1.352310180664
Output for 7.0.4
Ocramius: 0.50878524780273 Lastguest: 0.60796737670898 Lastguest: 0.57744979858398 Lastguest: 1.1892318725586
Output for 7.0.3
Ocramius: 0.49495697021484 Lastguest: 0.57625770568848 Lastguest: 0.54430961608887 Lastguest: 1.2431144714355
Output for 7.0.2
Ocramius: 0.41580200195312 Lastguest: 0.4878044128418 Lastguest: 0.46753883361816 Lastguest: 1.0368824005127
Output for 7.0.1
Ocramius: 0.33926963806152 Lastguest: 0.40459632873535 Lastguest: 0.40078163146973 Lastguest: 0.83637237548828
Output for 7.0.0
Ocramius: 0.33783912658691 Lastguest: 0.39315223693848 Lastguest: 0.38266181945801 Lastguest: 0.85210800170898
Output for 5.6.28
Ocramius: 1.1539459228515 Lastguest: 1.7311573028564 Lastguest: 1.6152858734131 Lastguest: 2.455472946167
Output for 5.6.21
Ocramius: 1.1746883392334 Lastguest: 1.9466876983642 Lastguest: 1.4984607696533 Lastguest: 2.2070407867432
Output for 5.6.20
Ocramius: 1.0483264923096 Lastguest: 1.1777877807617 Lastguest: 1.15966796875 Lastguest: 1.9090175628662
Output for 5.6.19
Ocramius: 0.89979171752929 Lastguest: 1.234769821167 Lastguest: 1.1982917785644 Lastguest: 1.7695426940918
Output for 5.6.18
Ocramius: 0.79154968261719 Lastguest: 1.1014938354492 Lastguest: 1.0371208190918 Lastguest: 1.4686584472656
Output for 5.6.17
Ocramius: 0.78415870666504 Lastguest: 0.90575218200683 Lastguest: 0.88405609130859 Lastguest: 1.4464855194092
Output for 5.6.16
Ocramius: 1.0576248168945 Lastguest: 1.2128353118896 Lastguest: 1.1544227600097 Lastguest: 1.8179416656494
Output for 5.6.15
Ocramius: 1.2338161468506 Lastguest: 1.4526844024658 Lastguest: 1.4035701751709 Lastguest: 2.0730495452881
Output for 5.6.14
Ocramius: 1.1730194091797 Lastguest: 1.392126083374 Lastguest: 1.3496875762939 Lastguest: 2.1710395812988
Output for 5.6.13
Ocramius: 0.99682807922363 Lastguest: 1.15966796875 Lastguest: 1.1200904846191 Lastguest: 1.7244815826416
Output for 5.6.12
Ocramius: 0.7326602935791 Lastguest: 1.4162063598633 Lastguest: 0.81968307495117 Lastguest: 1.4536380767822
Output for 5.6.11
Ocramius: 1.2509822845459 Lastguest: 1.3656616210937 Lastguest: 1.3816356658935 Lastguest: 2.1471977233887
Output for 5.6.10
Ocramius: 1.0261535644531 Lastguest: 1.1882781982422 Lastguest: 1.1720657348633 Lastguest: 1.8174648284912
Output for 5.6.9
Ocramius: 0.96511840820312 Lastguest: 1.124382019043 Lastguest: 1.1048316955566 Lastguest: 1.7974376678467
Output for 5.6.8
Ocramius: 1.2497901916504 Lastguest: 1.3711452484131 Lastguest: 1.3802051544189 Lastguest: 2.1266937255859
Output for 5.5.35
Ocramius: 1.0449886322021 Lastguest: 1.3434886932373 Lastguest: 1.3241767883301 Lastguest: 1.9288063049316
Output for 5.5.34
Ocramius: 1.176118850708 Lastguest: 1.431941986084 Lastguest: 1.3744831085205 Lastguest: 1.9388198852539
Output for 5.5.33
Ocramius: 0.95152854919433 Lastguest: 1.3577938079834 Lastguest: 1.3623237609863 Lastguest: 1.711368560791
Output for 5.5.32
Ocramius: 1.0695457458496 Lastguest: 1.333475112915 Lastguest: 1.2781620025635 Lastguest: 1.8839836120605
Output for 5.5.31
Ocramius: 0.76603889465332 Lastguest: 0.95200538635254 Lastguest: 0.91361999511718 Lastguest: 1.4033317565918
Output for 5.5.30
Ocramius: 0.96726417541503 Lastguest: 1.2037754058838 Lastguest: 1.1613368988037 Lastguest: 1.6536712646484
Output for 5.5.29
Ocramius: 0.75364112854004 Lastguest: 0.92983245849609 Lastguest: 0.94890594482422 Lastguest: 1.4979839324951
Output for 5.5.28
Ocramius: 1.15966796875 Lastguest: 1.4774799346924 Lastguest: 1.4522075653076 Lastguest: 2.1789073944092
Output for 5.5.27
Ocramius: 1.2526512145996 Lastguest: 1.4710426330566 Lastguest: 1.4729499816894 Lastguest: 2.1789073944092
Output for 5.5.26
Ocramius: 0.93722343444824 Lastguest: 0.95176696777343 Lastguest: 0.90980529785156 Lastguest: 1.3751983642578
Output for 5.5.25
Ocramius: 1.3220310211181 Lastguest: 1.5287399291992 Lastguest: 1.4622211456299 Lastguest: 2.1491050720215
Output for 5.5.24
Ocramius: 0.76866149902344 Lastguest: 0.93770027160644 Lastguest: 0.89836120605468 Lastguest: 1.4417171478271
Output for 5.4.45
Ocramius: 1.2247562408447 Lastguest: 1.7096996307373 Lastguest: 1.6267299652099 Lastguest: 3.6780834197998
Output for 5.4.44
Ocramius: 1.2454986572265 Lastguest: 1.9266605377197 Lastguest: 1.694917678833 Lastguest: 2.363920211792
Output for 5.4.43
Ocramius: 1.1582374572754 Lastguest: 1.8737316131592 Lastguest: 1.565933227539 Lastguest: 2.2726058959961
Output for 5.4.42
Ocramius: 1.2938976287842 Lastguest: 3.6408901214599 Lastguest: 1.7814636230469 Lastguest: 2.4137496948242
Output for 5.4.41
Ocramius: 1.2881755828857 Lastguest: 1.8379688262939 Lastguest: 2.3438930511474 Lastguest: 3.3988952636718
Output for 5.4.40
Ocramius: 1.2435913085937 Lastguest: 1.7545223236084 Lastguest: 1.7745494842529 Lastguest: 2.1710395812988
Output for 5.4.39
Ocramius: 1.4753341674804 Lastguest: 1.7910003662109 Lastguest: 1.7642974853516 Lastguest: 2.2387504577637
Output for 5.4.38
Ocramius: 1.4219284057617 Lastguest: 1.7797946929932 Lastguest: 1.5802383422851 Lastguest: 2.2180080413818
Output for 5.4.37
Ocramius: 1.2798309326172 Lastguest: 1.3051033020019 Lastguest: 1.2068748474121 Lastguest: 1.9207000732422
Output for 5.4.36
Ocramius: 0.99110603332519 Lastguest: 1.4147758483887 Lastguest: 1.4317035675049 Lastguest: 1.9142627716064
Output for 5.4.35
Ocramius: 1.0700225830078 Lastguest: 1.4393329620361 Lastguest: 1.3542175292969 Lastguest: 1.6748905181885
Output for 5.4.34
Ocramius: 1.0359287261963 Lastguest: 1.52587890625 Lastguest: 1.3570785522461 Lastguest: 1.7063617706299
Output for 5.4.32
Ocramius: 1.1055469512939 Lastguest: 1.699686050415 Lastguest: 1.4290809631347 Lastguest: 1.6682147979736
Output for 5.4.31
Ocramius: 1.0764598846435 Lastguest: 1.3926029205322 Lastguest: 1.2753009796142 Lastguest: 1.7709732055664
Output for 5.4.30
Ocramius: 1.0931491851806 Lastguest: 1.4846324920654 Lastguest: 1.2550354003906 Lastguest: 1.6512870788574
Output for 5.4.29
Ocramius: 0.97918510437011 Lastguest: 1.410961151123 Lastguest: 1.279354095459 Lastguest: 1.7311573028564
Output for 5.4.28
Ocramius: 2.2006034851074 Lastguest: 3.4224987030029 Lastguest: 3.1516551971435 Lastguest: 4.1289329528808
Output for 5.4.27
Ocramius: 1.1091232299805 Lastguest: 1.5106201171875 Lastguest: 1.4982223510742 Lastguest: 1.8763542175293
Output for 5.4.26
Ocramius: 0.99587440490722 Lastguest: 1.5256404876709 Lastguest: 1.5544891357422 Lastguest: 1.6756057739258
Output for 5.4.25
Ocramius: 1.0933876037598 Lastguest: 1.3811588287353 Lastguest: 1.3213157653808 Lastguest: 1.5950202941894
Output for 5.4.24
Ocramius: 1.0595321655273 Lastguest: 1.6939640045166 Lastguest: 1.6520023345947 Lastguest: 2.0344257354736
Output for 5.4.23
Ocramius: 1.5878677368164 Lastguest: 2.2857189178467 Lastguest: 1.9276142120361 Lastguest: 2.0759105682373
Output for 5.4.22
Ocramius: 3.2978057861328 Lastguest: 3.3688545227051 Lastguest: 3.772497177124 Lastguest: 3.9637088775635
Output for 5.4.21
Ocramius: 1.4066696166992 Lastguest: 2.0194053649902 Lastguest: 1.8072128295898 Lastguest: 2.1121501922607
Output for 5.4.20
Ocramius: 1.4183521270752 Lastguest: 2.1157264709472 Lastguest: 1.690149307251 Lastguest: 2.0029544830322
Output for 5.4.19
Ocramius: 2.9146671295166 Lastguest: 3.4670829772949 Lastguest: 3.0515193939209 Lastguest: 3.4103393554687
Output for 5.4.18
Ocramius: 2.8235912322998 Lastguest: 3.3187866210937 Lastguest: 2.8789043426514 Lastguest: 3.4646987915039
Output for 5.4.17
Ocramius: 1.4054775238037 Lastguest: 2.1874904632568 Lastguest: 1.5943050384521 Lastguest: 2.1488666534424
Output for 5.4.16
Ocramius: 1.8353462219238 Lastguest: 3.1909942626953 Lastguest: 1.5411376953125 Lastguest: 2.4178028106689
Output for 5.4.15
Ocramius: 2.1388530731201 Lastguest: 2.6981830596924 Lastguest: 1.591682434082 Lastguest: 2.1026134490967
Output for 5.4.14
Ocramius: 3.6537647247314 Lastguest: 3.7040710449219 Lastguest: 3.4694671630859 Lastguest: 4.9440860748291
Output for 5.4.13
Ocramius: 1.626968383789 Lastguest: 2.2063255310058 Lastguest: 1.7092227935791 Lastguest: 2.1259784698486
Output for 5.4.12
Ocramius: 1.3208389282226 Lastguest: 1.8117427825928 Lastguest: 1.7778873443603 Lastguest: 2.1755695343018
Output for 5.4.11
Ocramius: 3.0100345611572 Lastguest: 3.2851696014404 Lastguest: 2.9032230377197 Lastguest: 3.650426864624
Output for 5.4.10
Ocramius: 1.4407634735107 Lastguest: 2.1419525146484 Lastguest: 1.7025470733642 Lastguest: 1.9369125366211
Output for 5.4.9
Ocramius: 1.8479824066162 Lastguest: 2.2459030151367 Lastguest: 1.7540454864502 Lastguest: 2.063512802124
Output for 5.4.8
Ocramius: 2.0911693572998 Lastguest: 3.772497177124 Lastguest: 3.2680034637451 Lastguest: 3.5338401794433
Output for 5.4.7
Ocramius: 2.13623046875 Lastguest: 3.1242370605469 Lastguest: 2.9823780059814 Lastguest: 5.2988529205323
Output for 5.4.6
Ocramius: 1.1370182037353 Lastguest: 1.8308162689209 Lastguest: 2.1800994873047 Lastguest: 2.249002456665
Output for 5.4.5
Ocramius: 1.3465881347656 Lastguest: 2.1123886108398 Lastguest: 1.5530586242676 Lastguest: 2.0496845245361
Output for 5.4.4
Ocramius: 1.8229484558105 Lastguest: 2.173900604248 Lastguest: 1.7399787902832 Lastguest: 2.3281574249267
Output for 5.4.3
Ocramius: 1.48606300354 Lastguest: 2.0918846130371 Lastguest: 1.9209384918213 Lastguest: 3.7252902984619
Output for 5.4.2
Ocramius: 1.6372203826904 Lastguest: 2.0906925201416 Lastguest: 1.7530918121338 Lastguest: 2.4540424346924
Output for 5.4.1
Ocramius: 1.4173984527588 Lastguest: 2.4542808532715 Lastguest: 1.9915103912353 Lastguest: 3.3245086669922
Output for 5.4.0
Ocramius: 1.2400150299072 Lastguest: 1.6391277313232 Lastguest: 2.0210742950439 Lastguest: 2.2647380828857
Output for 5.3.29
Ocramius: 1.457929611206 Lastguest: 1.9934177398682 Lastguest: 1.7552375793457 Lastguest: 1.4550685882568
Output for 5.3.28
Ocramius: 2.0105838775635 Lastguest: 2.439022064209 Lastguest: 2.1517276763916 Lastguest: 2.0341873168945
Output for 5.3.27
Ocramius: 2.5055408477783 Lastguest: 2.9582977294922 Lastguest: 2.5529861450195 Lastguest: 1.7757415771484
Output for 5.3.26
Ocramius: 3.3695697784424 Lastguest: 3.1561851501465 Lastguest: 2.3128986358642 Lastguest: 1.727819442749
Output for 5.3.25
Ocramius: 3.35693359375 Lastguest: 4.1847229003906 Lastguest: 3.7126541137695 Lastguest: 3.1673908233642
Output for 5.3.24
Ocramius: 2.8440952301025 Lastguest: 4.5199394226074 Lastguest: 2.227783203125 Lastguest: 1.8525123596191
Output for 5.3.23
Ocramius: 2.7127265930175 Lastguest: 2.5591850280762 Lastguest: 2.298355102539 Lastguest: 1.9295215606689
Output for 5.3.22
Ocramius: 2.0153522491455 Lastguest: 2.3500919342041 Lastguest: 2.0992755889893 Lastguest: 3.9525032043457
Output for 5.3.21
Ocramius: 2.5427341461181 Lastguest: 2.7546882629394 Lastguest: 2.4394989013672 Lastguest: 1.9576549530029
Output for 5.3.20
Ocramius: 3.9429664611816 Lastguest: 3.0772686004638 Lastguest: 2.2556781768799 Lastguest: 1.7704963684082
Output for 5.3.19
Ocramius: 1.6679763793945 Lastguest: 2.3624897003174 Lastguest: 2.7401447296142 Lastguest: 2.0723342895508
Output for 5.3.18
Ocramius: 3.2315254211426 Lastguest: 4.1155815124511 Lastguest: 3.6244392395019 Lastguest: 3.2029151916504
Output for 5.3.17
Ocramius: 3.901720046997 Lastguest: 5.1929950714112 Lastguest: 4.854440689087 Lastguest: 4.277229309082
Output for 5.3.16
Ocramius: 2.1357536315918 Lastguest: 2.4769306182861 Lastguest: 2.1059513092041 Lastguest: 1.9693374633789
Output for 5.3.15
Ocramius: 4.1964054107666 Lastguest: 5.9409141540527 Lastguest: 5.9843063354492 Lastguest: 6.3016414642335
Output for 5.3.14
Ocramius: 2.5253295898437 Lastguest: 2.9051303863525 Lastguest: 2.2664070129394 Lastguest: 2.0663738250732
Output for 5.3.13
Ocramius: 2.4526119232178 Lastguest: 2.9010772705078 Lastguest: 2.382755279541 Lastguest: 1.8627643585205
Output for 5.3.12
Ocramius: 2.2609233856201 Lastguest: 2.551794052124 Lastguest: 2.0465850830078 Lastguest: 1.868724822998
Output for 5.3.11
Ocramius: 2.5670528411865 Lastguest: 2.8834342956543 Lastguest: 2.1891593933105 Lastguest: 1.7774105072021
Output for 5.3.10
Ocramius: 2.483606338501 Lastguest: 2.6881694793701 Lastguest: 2.0291805267334 Lastguest: 1.7924308776855
Output for 5.3.9
Ocramius: 3.2792091369629 Lastguest: 3.1776428222656 Lastguest: 4.213809967041 Lastguest: 3.1518936157226
Output for 5.3.8
Ocramius: 4.1360855102539 Lastguest: 3.9906501770019 Lastguest: 3.5030841827392 Lastguest: 3.3094882965088
Output for 5.3.7
Ocramius: 2.1436214447021 Lastguest: 2.516508102417 Lastguest: 2.2292137145996 Lastguest: 3.3113956451416
Output for 5.3.6
Ocramius: 3.7553310394287 Lastguest: 4.7032833099366 Lastguest: 4.4467449188232 Lastguest: 3.7670135498047
Output for 5.3.5
Ocramius: 2.5231838226318 Lastguest: 3.0033588409424 Lastguest: 2.3558139801025 Lastguest: 2.8083324432373
Output for 5.3.4
Ocramius: 3.0126571655273 Lastguest: 3.9834976196289 Lastguest: 3.7069320678711 Lastguest: 3.3512115478516
Output for 5.3.3
Ocramius: 1.7590522766113 Lastguest: 2.4716854095459 Lastguest: 2.5761127471924 Lastguest: 2.2072792053223
Output for 5.3.2
Ocramius: 2.2175312042236 Lastguest: 3.0784606933594 Lastguest: 2.6822090148926 Lastguest: 1.8572807312012
Output for 5.3.1
Ocramius: 3.1554698944092 Lastguest: 2.9842853546142 Lastguest: 2.1700859069824 Lastguest: 2.1724700927734
Output for 5.3.0
Ocramius: 3.5784244537353 Lastguest: 4.4498443603516 Lastguest: 4.0712356567383 Lastguest: 3.9789676666259
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /in/QK8Wu on line 69
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /in/QK8Wu on line 69
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/QK8Wu on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/QK8Wu on line 11
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/QK8Wu on line 11
Process exited with code 255.