3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Bar { } class Foo { private $bar; public function __construct(Bar $bar) { $this->bar = $bar; } } $reflect = new ReflectionClass('foo'); $constructor = $reflect->getConstructor(); $bar = new Bar; $aBar = [$bar]; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = new Foo($bar); } $t2 = microtime(true); echo 'new keyword: ' . ($t2-$t1) . "\n\n"; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = $reflect->newInstanceArgs([$bar]); } $t2 = microtime(true); echo 'newinstanceargs: ' . ($t2-$t1) . "\n\n"; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = $reflect->newInstanceWithoutConstructor(); $constructor->invokeArgs($foo, [$bar]); } $t2 = microtime(true); echo 'newinstancewithoutconstructor: ' . ($t2-$t1) . "\n\n"; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = new Foo(...$aBar); } $t2 = microtime(true); print_r($foo); echo 'vradic: ' . ($t2-$t1) . "\n\n";
based on 3HL85
Output for 7.1.0
new keyword: 0.0017158985137939 newinstanceargs: 0.0035421848297119 newinstancewithoutconstructor: 0.0041189193725586 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0018110275268555
Output for 7.0.14
new keyword: 0.0016400814056396 newinstanceargs: 0.0031330585479736 newinstancewithoutconstructor: 0.004054069519043 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0017530918121338
Output for 7.0.6
new keyword: 0.0010459423065186 newinstanceargs: 0.0022180080413818 newinstancewithoutconstructor: 0.0025901794433594 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0011389255523682
Output for 7.0.5
new keyword: 0.0014400482177734 newinstanceargs: 0.0029881000518799 newinstancewithoutconstructor: 0.0034999847412109 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0014970302581787
Output for 7.0.4
new keyword: 0.0014090538024902 newinstanceargs: 0.0029008388519287 newinstancewithoutconstructor: 0.0033941268920898 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0014350414276123
Output for 7.0.3
new keyword: 0.0020580291748047 newinstanceargs: 0.0031960010528564 newinstancewithoutconstructor: 0.003154993057251 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0016460418701172
Output for 7.0.2
new keyword: 0.001162052154541 newinstanceargs: 0.0030069351196289 newinstancewithoutconstructor: 0.0038399696350098 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0013558864593506
Output for 7.0.1
new keyword: 0.0016050338745117 newinstanceargs: 0.0035169124603271 newinstancewithoutconstructor: 0.0039479732513428 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0016331672668457
Output for 7.0.0
new keyword: 0.0010461807250977 newinstanceargs: 0.002249002456665 newinstancewithoutconstructor: 0.0025980472564697 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0011539459228516
Output for 5.6.28
new keyword: 0.0044739246368408 newinstanceargs: 0.0084228515625 newinstancewithoutconstructor: 0.0099418163299561 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0044140815734863
Output for 5.6.21
new keyword: 0.0041589736938477 newinstanceargs: 0.0083069801330566 newinstancewithoutconstructor: 0.009227991104126 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0048248767852783
Output for 5.6.20
new keyword: 0.0026071071624756 newinstanceargs: 0.0051078796386719 newinstancewithoutconstructor: 0.0059161186218262 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0032801628112793
Output for 5.6.19
new keyword: 0.003774881362915 newinstanceargs: 0.0068809986114502 newinstancewithoutconstructor: 0.0077991485595703 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0038430690765381
Output for 5.6.18
new keyword: 0.0025789737701416 newinstanceargs: 0.0046188831329346 newinstancewithoutconstructor: 0.0053741931915283 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0027320384979248
Output for 5.6.17
new keyword: 0.0036811828613281 newinstanceargs: 0.0070860385894775 newinstancewithoutconstructor: 0.0079779624938965 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0043609142303467
Output for 5.6.16
new keyword: 0.002586841583252 newinstanceargs: 0.0050928592681885 newinstancewithoutconstructor: 0.0059568881988525 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0037949085235596
Output for 5.6.15
new keyword: 0.0032479763031006 newinstanceargs: 0.0067789554595947 newinstancewithoutconstructor: 0.0071988105773926 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0041937828063965
Output for 5.6.14
new keyword: 0.0042328834533691 newinstanceargs: 0.0086581707000732 newinstancewithoutconstructor: 0.0092849731445312 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.004828929901123
Output for 5.6.13
new keyword: 0.0034208297729492 newinstanceargs: 0.0068538188934326 newinstancewithoutconstructor: 0.007328987121582 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0041360855102539
Output for 5.6.12
new keyword: 0.0040390491485596 newinstanceargs: 0.0078840255737305 newinstancewithoutconstructor: 0.0088109970092773 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0047211647033691
Output for 5.6.11
new keyword: 0.0043039321899414 newinstanceargs: 0.0084109306335449 newinstancewithoutconstructor: 0.00801682472229 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0043461322784424
Output for 5.6.10
new keyword: 0.0038931369781494 newinstanceargs: 0.0076301097869873 newinstancewithoutconstructor: 0.008516788482666 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0045449733734131
Output for 5.6.9
new keyword: 0.0040059089660645 newinstanceargs: 0.0077240467071533 newinstancewithoutconstructor: 0.0085768699645996 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0046989917755127
Output for 5.6.8
new keyword: 0.0036270618438721 newinstanceargs: 0.0071630477905273 newinstancewithoutconstructor: 0.0087590217590332 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0042710304260254
Output for 5.6.7
new keyword: 0.0027170181274414 newinstanceargs: 0.005363941192627 newinstancewithoutconstructor: 0.0061171054840088 Foo Object ( [bar:Foo:private] => Bar Object ( ) ) vradic: 0.0038001537322998
Output for 5.5.24 - 5.5.35
Parse error: syntax error, unexpected '.' in /in/1a1A2 on line 56
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '.', expecting ')' in /in/1a1A2 on line 56
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/1a1A2 on line 19
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/1a1A2 on line 19
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/1a1A2 on line 7
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/1a1A2 on line 7
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/1a1A2 on line 7
Process exited with code 255.