3v4l.org

run code in 300+ PHP versions simultaneously
<?php function call_user_func_fixed() { // Not much point in writing all that logic out twice, just require that both fixer functions are present $args = func_get_args(); $callable = array_shift($args); return call_user_func_array_fixed($callable, $args); } function call_user_func_array_fixed($callable, $args) { $isStaticMethod = false; // Normalize the $callable and see if it looks like a static method if (is_object($callable) && $callable instanceof Closure) { $func = $callable; } else if (is_string($callable)) { $expr = '/^([a-z_\x7f-\xff][\w\x7f-\xff]*)::([a-z_\x7f-\xff][\w\x7f-\xff]*)$/i'; if (preg_match($expr, $callable, $matches)) { $func = array($matches[1], $matches[2]); $isStaticMethod = true; } else { $func = $callable; } } else if (is_array($callable) && isset($callable[0], $callable[1]) && count($callable) === 2) { if (is_object($callable[0])) { $func = $callable; } else if (is_string($callable[0])) { $func = $callable; $isStaticMethod = true; } } // If it's not a valid callable give up here if (!isset($callable) || (!$isStaticMethod && !is_callable($callable))) { trigger_error('call_user_func() expects parameter 1 to be a valid callback', E_USER_WARNING); return null; } // If it's not a static method use the regular mechanism if (!$isStaticMethod) { return call_user_func_array($func, $args); } // Get some info about how we were called $backtrace = debug_backtrace(); // passing args here is fraught with complications for backwards compat :-( if ($backtrace[1]['function'] === 'call_user_func_fixed') { $called = 'call_user_func_fixed'; $contextClass = !empty($backtrace[2]['class']) ? $backtrace[2]['class'] : null; } else { $called = 'call_user_func_array_fixed'; $contextClass = !empty($backtrace[1]['class']) ? $backtrace[1]['class'] : null; } $key = $backtrace[1]['function'] === 'call_user_func_fixed' ? 2 : 1; // Get a reference to the target static method if possible try { if ($func[0] === 'self') { if (!$contextClass) { throw new Exception('Use of self in an invalid context'); } $class = new ReflectionClass($contextClass); $method = $class->getMethod($func[1]); if ($method->isPrivate()) { if ($method->getDeclaringClass()->getName() !== $contextClass || !method_exists($method, 'setAccessible')) { throw new Exception('Attempting to call private method in an invalid context'); } $method->setAccessible(true); } else if ($method->isProtected()) { if (!method_exists($method, 'setAccessible')) { throw new Exception('Attempting to call protected method in an invalid context'); } while ($class->getName() !== $contextClass) { $class = $class->getParentClass(); } if ($class->getName() !== $contextClass) { throw new Exception('Attempting to call protected method in an invalid context'); } $method->setAccessible(true); } } else if ($func[0] === 'static' && function_exists('get_called_class')) { $class = new ReflectionClass(get_called_class()); $method = $class->getMethod($func[1]); } else { $class = new ReflectionClass($func[0]); $method = $class->getMethod($func[1]); } // Invoke the method with the passed arguments and return the result return $method->invokeArgs(null, $args); } catch (Exception $e) { trigger_error('call_user_func*() expects parameter 1 to be a valid callback: ' . $e->getMessage(), E_USER_WARNING); return null; } // Invoke the method with the passed arguments and return the result return $method->invokeArgs(null, $args); } class Car { public function run() { return call_user_func_fixed('static::getName'); // should call toyota } private static function getName() { return 'Car'; } } class Toyota extends Car { public static function getName() { return 'Toyota'; } } $car = new Car(); echo $car->run(); //Car instead of Toyota $toyota = new Toyota(); echo $toyota->run(); //Car instead of Toyota

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0090.01316.75
8.3.50.0150.00917.67
8.3.40.0060.01019.02
8.3.30.0120.00318.81
8.3.20.0120.00318.93
8.3.10.0040.00420.77
8.3.00.0040.00717.88
8.2.180.0100.01017.00
8.2.170.0070.01122.96
8.2.160.0080.00520.67
8.2.150.0030.00624.18
8.2.140.0030.00524.66
8.2.130.0000.00826.16
8.2.120.0060.00320.08
8.2.110.0030.00720.92
8.2.100.0060.00618.28
8.2.90.0030.00619.47
8.2.80.0040.00718.18
8.2.70.0030.00617.88
8.2.60.0060.00318.05
8.2.50.0040.00418.07
8.2.40.0000.00818.41
8.2.30.0040.00418.32
8.2.20.0040.00417.95
8.2.10.0040.00418.00
8.2.00.0050.00518.13
8.1.280.0150.00025.92
8.1.270.0050.00324.66
8.1.260.0090.00026.35
8.1.250.0040.00428.09
8.1.240.0040.00820.94
8.1.230.0100.00321.01
8.1.220.0000.00817.79
8.1.210.0040.00418.82
8.1.200.0060.00317.63
8.1.190.0040.00417.68
8.1.180.0090.00018.10
8.1.170.0080.00019.02
8.1.160.0080.00019.05
8.1.150.0040.00418.89
8.1.140.0090.00017.62
8.1.130.0070.00017.86
8.1.120.0040.00417.61
8.1.110.0050.00317.67
8.1.100.0000.00717.78
8.1.90.0000.00717.73
8.1.80.0000.00817.54
8.1.70.0000.00717.64
8.1.60.0060.00317.82
8.1.50.0090.00017.64
8.1.40.0080.00017.80
8.1.30.0000.00817.88
8.1.20.0000.01017.95
8.1.10.0040.00417.91
8.1.00.0030.00617.81
8.0.300.0060.00320.15
8.0.290.0000.00917.00
8.0.280.0040.00418.52
8.0.270.0040.00417.38
8.0.260.0030.00317.01
8.0.250.0070.00017.18
8.0.240.0040.00417.30
8.0.230.0070.00017.15
8.0.220.0040.00417.23
8.0.210.0030.00317.25
8.0.200.0030.00617.20
8.0.190.0000.00917.23
8.0.180.0040.00417.28
8.0.170.0030.00617.21
8.0.160.0000.00717.21
8.0.150.0030.00517.13
8.0.140.0030.00717.01
8.0.130.0060.00013.68
8.0.120.0000.00817.18
8.0.110.0040.00417.17
8.0.100.0000.00817.23
8.0.90.0000.00817.32
8.0.80.0090.00617.23
8.0.70.0000.00817.02
8.0.60.0000.00817.01
8.0.50.0080.00017.15
8.0.30.0080.01117.33
8.0.20.0120.00617.25
8.0.10.0050.00217.43
8.0.00.0090.00917.09
7.4.330.0030.00313.21
7.4.320.0030.00316.83
7.4.300.0070.00016.68
7.4.290.0060.00316.79
7.4.280.0040.00416.96
7.4.270.0080.00016.91
7.4.260.0030.00313.71
7.4.250.0050.00316.73
7.4.240.0050.00216.92
7.4.230.0040.00416.85
7.4.220.0160.00316.92
7.4.210.0060.00816.88
7.4.200.0040.00416.99
7.4.190.0000.00716.87
7.4.160.0000.01616.79
7.4.150.0160.01616.81
7.4.140.0180.00816.79
7.4.130.0130.00616.81
7.4.120.0110.00616.89
7.4.110.0100.00717.02
7.4.100.0180.00016.80
7.4.90.0070.01116.88
7.4.80.0100.00816.89
7.4.70.0200.00916.96
7.4.60.0140.00716.79
7.4.50.0060.00316.94
7.4.40.0100.00716.70
7.4.30.0090.00616.96
7.4.10.0100.01015.18
7.4.00.0070.00715.22
7.3.330.0030.00413.70
7.3.320.0030.00313.50
7.3.310.0050.00216.54
7.3.300.0040.00416.54
7.3.290.0040.01116.71
7.3.280.0130.00616.67
7.3.270.0060.01216.85
7.3.260.0170.00316.63
7.3.250.0060.01516.70
7.3.240.0140.00716.95
7.3.230.0100.00616.84
7.3.210.0170.00316.63
7.3.200.0060.01419.39
7.3.190.0070.01116.65
7.3.180.0100.00616.72
7.3.170.0120.00616.85
7.3.160.0060.00916.60
7.3.130.0000.01515.15
7.3.120.0020.01315.02
7.3.110.0100.00715.06
7.3.100.0030.01415.14
7.3.90.0140.00315.22
7.3.80.0070.00714.94
7.3.70.0030.01615.01
7.3.60.0090.00615.05
7.3.50.0060.01215.08
7.3.40.0060.00615.19
7.3.30.0030.01014.82
7.3.20.0110.00416.87
7.3.10.0040.00916.71
7.3.00.0080.00316.86
7.2.330.0110.00716.98
7.2.320.0080.01716.97
7.2.310.0110.01116.95
7.2.300.0140.01217.02
7.2.290.0120.00616.81
7.2.260.0120.00915.42
7.2.250.0100.01015.38
7.2.240.0090.00915.39
7.2.230.0000.01415.57
7.2.220.0070.01015.27
7.2.210.0070.00715.33
7.2.200.0050.00515.21
7.2.190.0130.00615.21
7.2.180.0130.00615.32
7.2.170.0090.00015.06
7.2.160.0040.01215.20
7.2.150.0030.01017.17
7.2.140.0060.00617.13
7.2.130.0070.01017.11
7.2.120.0040.01117.16
7.2.110.0060.00917.22
7.2.100.0030.00917.13
7.2.90.0080.00417.02
7.2.80.0100.00717.18
7.2.70.0060.00817.25
7.2.60.0070.01016.95
7.2.50.0030.00917.16
7.2.40.0060.00317.29
7.2.30.0060.00917.20
7.2.20.0060.00917.32
7.2.10.0060.00617.20
7.2.00.0080.00818.51
7.1.330.0120.00316.13
7.1.320.0070.00716.10
7.1.310.0030.00916.10
7.1.300.0000.01415.84
7.1.290.0000.01716.13
7.1.280.0060.00616.04
7.1.270.0100.00616.14
7.1.260.0060.00315.96
7.1.250.0000.00916.08
7.1.240.0110.00415.89
7.1.230.0000.01015.98
7.1.220.0060.00615.99
7.1.210.0060.00615.90
7.1.200.0050.00616.04
7.1.190.0060.00915.95
7.1.180.0070.00716.09
7.1.170.0000.00915.82
7.1.160.0090.00015.74
7.1.150.0120.00316.13
7.1.140.0030.01016.00
7.1.130.0060.00316.14
7.1.120.0110.00316.02
7.1.110.0090.00316.09
7.1.100.0030.00716.22
7.1.90.0000.01215.99
7.1.80.0060.01016.10
7.1.70.0060.00616.65
7.1.60.0050.00916.66
7.1.50.0030.01116.66
7.1.40.0090.00616.12
7.1.30.0030.00915.82
7.1.20.0000.01715.97
7.1.10.0000.01415.85
7.1.00.0050.04219.19
7.0.330.0080.00415.52
7.0.320.0030.00615.43
7.0.310.0000.01715.57
7.0.300.0070.00715.32
7.0.290.0060.00315.64
7.0.280.0030.00615.55
7.0.270.0090.00315.62
7.0.260.0030.00615.24
7.0.250.0080.00815.73
7.0.240.0030.01015.55
7.0.230.0040.00415.67
7.0.220.0040.00815.75
7.0.210.0000.01515.68
7.0.200.0060.00616.36
7.0.190.0000.01015.61
7.0.180.0070.00715.58
7.0.170.0030.00615.79
7.0.160.0000.00915.74
7.0.150.0070.00715.58
7.0.140.0050.03818.94
7.0.130.0040.01115.75
7.0.120.0070.03918.88
7.0.110.0160.02317.85
7.0.100.0160.02017.71
7.0.90.0170.03917.78
7.0.80.0120.02517.96
7.0.70.0050.02517.85
7.0.60.0040.03417.91
7.0.50.0100.02017.96
7.0.40.0010.02616.84
7.0.30.0040.02616.98
7.0.20.0040.04916.82
7.0.10.0060.04316.87
7.0.00.0040.04116.92
5.6.400.0030.00714.33
5.6.390.0040.01114.46
5.6.380.0040.00414.86
5.6.370.0030.00914.45
5.6.360.0030.00914.45
5.6.350.0030.01014.58
5.6.340.0060.00614.82
5.6.330.0000.01614.20
5.6.320.0000.01314.81
5.6.310.0100.00714.68
5.6.300.0040.00714.51
5.6.290.0040.00714.35
5.6.280.0030.04317.62
5.6.270.0070.00314.54
5.6.260.0050.04817.56
5.6.250.0050.04117.47
5.6.240.0040.02417.57
5.6.230.0020.02817.61
5.6.220.0060.02517.66
5.6.210.0000.02917.56
5.6.200.0050.02717.64
5.6.190.0050.02517.79
5.6.180.0090.01917.78
5.6.170.0090.02417.72
5.6.160.0090.04017.77
5.6.150.0060.04317.89
5.6.140.0100.04517.75
5.6.130.0050.04717.88
5.6.120.0080.03817.97
5.6.110.0020.04917.70
5.6.100.0130.04017.72
5.6.90.0070.03917.84
5.6.80.0060.02317.51
5.6.70.0050.03817.47
5.6.60.0070.03817.50
5.6.50.0070.04217.37
5.6.40.0020.04217.40
5.6.30.0130.02217.50
5.6.20.0060.04217.42
5.6.10.0080.04017.37
5.6.00.0050.04317.43
5.5.380.0050.02217.34
5.5.370.0010.02817.46
5.5.360.0070.02317.60
5.5.350.0030.02517.42
5.5.340.0050.02517.67
5.5.330.0070.02217.66
5.5.320.0020.03217.67
5.5.310.0020.03017.62
5.5.300.0070.04217.72
5.5.290.0030.04717.72
5.5.280.0110.03517.67
5.5.270.0020.03717.87
5.5.260.0040.04617.63
5.5.250.0120.03517.70
5.5.240.0020.04617.29
5.5.230.0050.04217.31
5.5.220.0070.04317.32
5.5.210.0030.03917.42
5.5.200.0110.03817.46
5.5.190.0030.04317.10
5.5.180.0080.02117.40
5.5.170.0090.00414.42
5.5.160.0070.04017.27
5.5.150.0070.04317.34
5.5.140.0070.04417.47
5.5.130.0050.04217.16
5.5.120.0030.05017.25
5.5.110.0060.04617.34
5.5.100.0050.04317.35
5.5.90.0100.04217.17
5.5.80.0070.04417.41
5.5.70.0070.04417.12
5.5.60.0070.04017.34
5.5.50.0090.04017.13
5.5.40.0100.04317.41
5.5.30.0070.03017.25
5.5.20.0030.04617.10
5.5.10.0050.04717.28
5.5.00.0080.04217.34
5.4.450.0070.04215.34
5.4.440.0020.04715.31
5.4.430.0110.03515.31
5.4.420.0080.04215.41
5.4.410.0080.03815.11
5.4.400.0050.04115.08
5.4.390.0020.03415.04
5.4.380.0090.03715.17
5.4.370.0050.04115.15
5.4.360.0050.04015.09
5.4.350.0050.04415.19
5.4.340.0010.04315.02
5.4.330.0070.00710.93
5.4.320.0030.04415.08
5.4.310.0210.02515.10
5.4.300.0040.03215.09
5.4.290.0030.04314.93
5.4.280.0120.03715.15
5.4.270.0020.03715.06
5.4.260.0070.04215.23
5.4.250.0070.04515.11
5.4.240.0070.03715.12
5.4.230.0000.04515.11
5.4.220.0040.03115.21
5.4.210.0030.04015.13
5.4.200.0110.03515.21
5.4.190.0050.04014.93
5.4.180.0070.04115.14
5.4.170.0100.03915.14
5.4.160.0080.03215.04
5.4.150.0050.04315.26
5.4.140.0100.03713.88
5.4.130.0000.03913.82
5.4.120.0090.03913.88
5.4.110.0040.04113.90
5.4.100.0110.02413.81
5.4.90.0060.04013.84
5.4.80.0030.04113.67
5.4.70.0080.04013.70
5.4.60.0060.03613.88
5.4.50.0080.03813.77
5.4.40.0030.03813.68
5.4.30.0100.02013.91
5.4.20.0090.03813.81
5.4.10.0040.03813.76
5.4.00.0050.04013.49
5.3.290.0020.02912.67
5.3.280.0080.03812.61
5.3.270.0080.04012.73
5.3.260.0030.04312.77
5.3.250.0070.03512.75
5.3.240.0030.03012.62
5.3.230.0080.03812.66
5.3.220.0080.02912.63
5.3.210.0080.03912.63
5.3.200.0090.03612.60
5.3.190.0030.03812.69
5.3.180.0080.03612.83
5.3.170.0050.04612.85
5.3.160.0060.03912.63
5.3.150.0070.04012.68
5.3.140.0060.03512.81
5.3.130.0070.03712.50
5.3.120.0040.03312.71
5.3.110.0040.04112.67
5.3.100.0100.03312.47
5.3.90.0060.03712.36
5.3.80.0080.02512.43
5.3.70.0110.03312.32
5.3.60.0040.04412.42
5.3.50.0080.03812.33
5.3.40.0100.03612.30
5.3.30.0030.03512.35
5.3.20.0100.03712.27
5.3.10.0020.02912.11
5.3.00.0020.04712.15
5.2.170.0130.05311.73
5.2.160.0030.06311.73
5.2.150.0030.05711.73
5.2.140.0000.07011.73
5.2.130.0070.06011.73
5.2.120.0030.03711.73
5.2.110.0070.05711.73
5.2.100.0070.06011.73
5.2.90.0030.06311.73
5.2.80.0130.05711.73
5.2.70.0100.05311.73
5.2.60.0070.05011.73
5.2.50.0070.06311.73
5.2.40.0130.05011.73
5.2.30.0030.06011.73
5.2.20.0070.06011.73
5.2.10.0030.05711.73
5.2.00.0070.05711.73
5.1.60.0000.05311.73
5.1.50.0070.05011.73
5.1.40.0030.05311.73
5.1.30.0100.05311.73
5.1.20.0100.04711.73
5.1.10.0030.05311.73
5.1.00.0000.05711.73
5.0.50.0000.04711.73
5.0.40.0070.03311.73
5.0.30.0170.03011.73
5.0.20.0070.04311.73
5.0.10.0070.03311.73
5.0.00.0030.06011.73
4.4.90.0070.03011.73
4.4.80.0030.01711.73
4.4.70.0000.02711.73
4.4.60.0030.03311.73
4.4.50.0000.02311.73
4.4.40.0070.05011.73
4.4.30.0070.03011.73
4.4.20.0070.03311.73
4.4.10.0030.02011.73
4.4.00.0070.02311.73
4.3.110.0070.02711.73
4.3.100.0030.03311.73
4.3.90.0070.02711.73
4.3.80.0030.05311.73
4.3.70.0000.02711.73
4.3.60.0070.03311.73
4.3.50.0000.03711.73
4.3.40.0070.04711.73
4.3.30.0000.03711.73
4.3.20.0030.03711.73
4.3.10.0000.03711.73
4.3.00.0000.03311.73

preferences:
37.41 ms | 401 KiB | 5 Q