3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Hook class file * * @category Include * @package Slimium\Module\Core * @author Jakub Ďuraš <jkblmr@gmail.com> */ /** * Hook class- class for working with hooks * * -100 - lowest priority <br> * 100+ - highest priority <br> * 50 - default priority <br> * if the priority is already taken, the nearest free lower one is taken */ class hook { /** * List of hooks * @var array */ private static $hooks = []; /** * Call hooks and don't pass any returned value * @param string $hook_enviroment can be module name or other enviroment in which hook is located * @param string $hook_name name * @param mixed $argument argument to pass to hook * @return boolean TRUE if there are any hooks assigned and they were executed, FALSE in there are no hooks assigned */ public static function call($hook_enviroment, $hook_name, $argument = NULL) { //If there is any hooked function if (isset(self::$hooks[$hook_enviroment][$hook_name])) { //Sort array krsort(self::$hooks[$hook_enviroment][$hook_name]); //Loop thorugh array foreach (self::$hooks[$hook_enviroment][$hook_name] as $hook_function) { $hook_function($argument); } return true; }else{ return false; } } /** * Call hooks, let argument go through filtering and return filtered argument * @param string $hook_enviroment can be module name or other enviroment in which hook is located * @param string $hook_name name * @param mixed $argument argument to pass to hook * @return mixed filtered argument */ public static function filter($hook_enviroment, $hook_name, $argument = NULL) { //If there is any hooked function if (isset(self::$hooks[$hook_enviroment][$hook_name])) { //Sort array krsort(self::$hooks[$hook_enviroment][$hook_name]); $filtered = $argument; $first = true; //Loop thorugh array foreach (self::$hooks[$hook_enviroment][$hook_name] as $hook_function) { if($first){ $filtered = $hook_function($argument); $first = false; }else{ $filtered = $hook_function($argument, $filtered); } } return $filtered; } } /** * Add hook * @param string $hook_enviroment can be module name or other enviroment in which hook is located * @param string $hook_name name * @param callable $function name of the function of anonymous function to call * @param callable $priority priority of the hook, can be anything from 1(executed as last) to 100+(executed as first) if priority is already taken, the nearest free lower one is taken * @return integer priority at which hook was added */ public static function add($hook_enviroment, $hook_name, $function, $priority = 50) { //If we do not need to loop through prirorities if(!isset(self::$hooks[$hook_enviroment][$hook_name][$priority])){ self::$hooks[$hook_enviroment][$hook_name][$priority] = $function; return $priority; } //Loop through hooked functions to find nearest free priority for ($priority; $priority > -100; $priority--) { if(!isset(self::$hooks[$hook_enviroment][$hook_name][$priority])){ self::$hooks[$hook_enviroment][$hook_name][$priority] = $function; break; } } return $priority; } /** * Remove hook at certain priority * @param string $hook_enviroment can be module name or other enviroment in which hook is located * @param string $hook_name name * @param callable $priority priority of the hook to delete * @return boolean TRUE */ public static function remove($hook_enviroment, $hook_name, $priority) { unset(self::$hooks[$hook_enviroment][$hook_name][$priority]); return true; } /** * Remove hook all hooks of some name and in som enviroment * @param string $hook_enviroment can be module name or other enviroment in which hook is located * @param string $hook_name name * @return boolean TRUE */ public static function remove_all($hook_enviroment, $hook_name) { self::$hooks[$hook_enviroment][$hook_name] = []; return true; } /** * Is anything hooked at certain priority * @param string $hook_enviroment can be module name or other enviroment in which hook is located * @param string $hook_name name * @param callable $priority priority of the hook * @return boolean TRUE or FALSE */ public static function is_hooked($hook_enviroment, $hook_name, $priority) { if(isset(self::$hooks[$hook_enviroment][$hook_name][$priority])){ return true; }else{ return false; } } } hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::add('main', 'init', function(){$var = 'foo';}); hook::call('main', 'init');

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.0080.00816.75
8.3.50.0120.00722.94
8.3.40.0110.00418.97
8.3.30.0120.00318.98
8.3.20.0000.00720.20
8.3.10.0000.00823.61
8.3.00.0050.00317.46
8.2.180.0120.00316.50
8.2.170.0110.01122.96
8.2.160.0030.01020.25
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0000.00721.04
8.2.110.0080.00022.18
8.2.100.0100.00317.91
8.2.90.0080.00019.18
8.2.80.0030.00617.97
8.2.70.0000.00817.74
8.2.60.0060.00618.05
8.2.50.0030.00518.07
8.2.40.0040.00418.03
8.2.30.0070.00018.12
8.2.20.0040.00417.86
8.2.10.0030.00618.18
8.2.00.0000.00817.68
8.1.280.0090.00925.92
8.1.270.0040.00423.87
8.1.260.0020.00526.35
8.1.250.0050.00328.09
8.1.240.0000.00924.02
8.1.230.0070.00420.75
8.1.220.0090.00017.91
8.1.210.0030.00618.77
8.1.200.0100.00017.60
8.1.190.0040.00417.48
8.1.180.0040.00418.10
8.1.170.0000.00818.68
8.1.160.0040.00422.00
8.1.150.0000.00819.00
8.1.140.0040.00417.51
8.1.130.0000.00717.88
8.1.120.0070.00017.52
8.1.110.0040.00417.52
8.1.100.0070.00017.41
8.1.90.0030.00317.46
8.1.80.0040.00417.57
8.1.70.0050.00217.36
8.1.60.0040.00717.53
8.1.50.0040.00417.54
8.1.40.0000.00817.63
8.1.30.0030.00617.55
8.1.20.0020.00517.69
8.1.10.0030.00617.62
8.1.00.0040.00417.53
8.0.300.0040.00418.77
8.0.290.0000.00716.75
8.0.280.0000.00718.51
8.0.270.0000.00817.24
8.0.260.0030.00317.28
8.0.250.0030.00316.94
8.0.240.0000.00816.89
8.0.230.0030.00317.00
8.0.220.0020.00516.96
8.0.210.0000.00716.94
8.0.200.0000.00716.99
8.0.190.0080.00017.04
8.0.180.0000.00817.00
8.0.170.0040.00416.88
8.0.160.0050.00216.93
8.0.150.0000.00716.89
8.0.140.0060.00316.77
8.0.130.0070.00013.43
8.0.120.0050.00216.88
8.0.110.0050.00216.84
8.0.100.0000.00717.01
8.0.90.0000.00716.82
8.0.80.0140.00316.99
8.0.70.0050.00316.83
8.0.60.0040.00416.84
8.0.50.0000.00816.98
8.0.30.0120.01017.08
8.0.20.0090.01317.41
8.0.10.0070.00017.14
8.0.00.0110.00816.81
7.4.330.0000.00515.08
7.4.320.0000.00716.47
7.4.300.0000.00616.67
7.4.290.0030.00616.66
7.4.280.0040.00416.46
7.4.270.0030.00616.70
7.4.260.0050.00316.57
7.4.250.0050.00216.52
7.4.240.0020.00516.59
7.4.230.0080.00016.65
7.4.220.0180.00016.51
7.4.210.0130.00716.66
7.4.200.0000.00716.74
7.4.160.0080.00816.75
7.4.150.0090.00917.40
7.4.140.0160.00517.86
7.4.130.0100.01216.53
7.4.120.0140.00516.53
7.4.110.0100.00716.49
7.4.100.0160.00316.49
7.4.90.0070.01016.66
7.4.80.0100.01319.39
7.4.70.0080.01116.40
7.4.60.0110.00716.65
7.4.50.0000.00516.56
7.4.40.0030.01516.77
7.4.30.0030.01316.50
7.4.10.0040.01515.11
7.4.00.0110.00514.99
7.3.330.0030.00313.15
7.3.320.0030.00313.41
7.3.310.0030.00516.46
7.3.300.0070.00016.23
7.3.290.0150.00316.36
7.3.280.0070.00916.42
7.3.270.0070.01317.40
7.3.260.0140.00416.69
7.3.250.0090.01016.53
7.3.240.0100.00716.70
7.3.230.0130.00416.57
7.3.210.0070.01016.35
7.3.200.0130.00719.39
7.3.190.0030.01916.61
7.3.180.0160.00016.59
7.3.170.0090.00916.58
7.3.160.0090.01016.48
7.3.130.0080.00814.94
7.3.120.0090.00614.87
7.3.110.0090.00614.88
7.3.100.0110.00314.85
7.3.90.0000.00914.91
7.3.80.0110.00414.81
7.3.70.0060.01014.52
7.3.60.0060.00615.03
7.3.50.0000.01214.97
7.3.40.0070.00314.84
7.3.30.0070.00715.04
7.3.20.0070.01116.79
7.3.10.0040.01116.51
7.3.00.0030.01016.56
7.2.330.0150.01216.79
7.2.320.0160.00616.88
7.2.310.0040.01416.65
7.2.300.0130.00316.89
7.2.290.0060.01416.87
7.2.260.0110.00714.99
7.2.250.0060.01015.25
7.2.240.0070.00714.85
7.2.230.0030.01015.34
7.2.220.0100.00014.91
7.2.210.0070.00914.64
7.2.200.0040.01115.38
7.2.190.0060.00615.38
7.2.180.0120.00315.13
7.2.170.0030.01215.25
7.2.160.0100.00315.18
7.2.150.0060.00617.07
7.2.140.0030.01316.78
7.2.130.0060.00616.90
7.2.120.0040.00717.04
7.2.110.0130.00016.83
7.2.100.0090.00616.97
7.2.90.0040.00416.88
7.2.80.0030.01216.65
7.2.70.0030.01017.01
7.2.60.0030.00616.87
7.2.50.0000.01016.84
7.2.40.0040.00816.75
7.2.30.0000.01416.96
7.2.20.0040.00716.83
7.2.10.0040.01116.98
7.2.00.0050.01218.21
7.1.330.0070.01015.68
7.1.320.0090.00915.86
7.1.310.0000.01315.82
7.1.300.0100.00315.97
7.1.290.0040.00815.81
7.1.280.0030.01015.78
7.1.270.0060.00615.80
7.1.260.0070.01015.79
7.1.250.0070.00415.76
7.1.240.0060.00315.88
7.1.230.0040.00716.01
7.1.220.0070.00715.84
7.1.210.0090.00615.93
7.1.200.0050.00515.81
7.1.190.0060.00615.77
7.1.180.0090.00015.82
7.1.170.0030.00615.76
7.1.160.0040.00815.80
7.1.150.0040.01115.98
7.1.140.0040.00415.78
7.1.130.0030.01015.62
7.1.120.0050.00515.61
7.1.110.0030.01015.95
7.1.100.0040.00716.98
7.1.90.0040.00715.96
7.1.80.0000.01415.82
7.1.70.0050.01316.42
7.1.60.0080.00817.68
7.1.50.0130.01025.32
7.1.40.0000.01115.41
7.1.30.0000.00915.92
7.1.20.0000.00915.75
7.1.10.0140.00015.91
7.1.00.0030.04219.20
7.0.330.0040.00815.44
7.0.320.0060.00315.40
7.0.310.0030.01315.62
7.0.300.0030.01015.25
7.0.290.0080.00415.55
7.0.280.0100.00615.40
7.0.270.0100.00315.43
7.0.260.0000.01015.43
7.0.250.0030.00915.44
7.0.240.0070.00415.46
7.0.230.0090.00315.55
7.0.220.0030.00915.64
7.0.210.0070.00715.40
7.0.200.0030.00816.00
7.0.190.0030.00915.22
7.0.180.0040.00415.50
7.0.170.0100.00415.47
7.0.160.0060.00315.47
7.0.150.0040.00815.59
7.0.140.0040.04018.79
7.0.130.0130.00015.64
7.0.120.0060.00615.57
7.0.110.0030.01115.45
7.0.100.0040.01115.42
7.0.90.0000.01115.31
7.0.80.0070.00715.53
7.0.70.0030.00915.24
7.0.60.0050.04317.54
7.0.50.0050.04116.60
7.0.40.0110.03816.64
7.0.30.0100.02516.88
7.0.20.0180.04216.82
7.0.10.0080.02516.81
7.0.00.0030.03316.93
5.6.400.0030.01414.60
5.6.390.0100.00714.51
5.6.380.0070.00314.53
5.6.370.0030.01014.73
5.6.360.0070.00714.64
5.6.350.0070.00714.18
5.6.340.0070.01014.38
5.6.330.0040.01114.64
5.6.320.0120.00314.56
5.6.310.0040.00714.73
5.6.300.0070.00714.32
5.6.290.0040.00814.75
5.6.280.0030.04217.77
5.6.270.0040.01414.82
5.6.260.0030.01314.59
5.6.250.0030.01414.62
5.6.240.0060.01214.56
5.6.230.0000.01814.52
5.6.220.0070.00714.66
5.6.210.0130.03317.52
5.6.200.0080.03316.42
5.6.190.0070.02317.51
5.6.180.0140.04217.56
5.6.170.0150.04017.52
5.6.160.0040.02917.56
5.6.150.0040.03016.30
5.6.140.0020.04216.19
5.6.130.0010.04416.44
5.6.120.0080.04117.70
5.6.110.0080.03217.80
5.6.100.0080.04417.99
5.6.90.0090.04217.90
5.6.80.0050.04517.43
5.6.70.0070.00314.76
5.6.60.0060.00614.48
5.6.50.0030.01014.43
5.6.40.0060.00614.22
5.6.30.0120.00314.55
5.6.20.0070.00714.36
5.6.10.0000.01414.29
5.6.00.0040.00414.48
5.5.380.0130.00014.46
5.5.370.0070.00714.45
5.5.360.0100.00314.36
5.5.350.0120.02317.44
5.5.340.0050.04516.32
5.5.330.0070.04317.49
5.5.320.0120.02617.39
5.5.310.0170.04517.44
5.5.300.0020.04016.22
5.5.290.0080.03916.30
5.5.280.0100.03517.80
5.5.270.0070.02717.83
5.5.260.0060.04617.71
5.5.250.0120.03717.71
5.5.240.0050.01817.41
5.5.230.0070.00314.32
5.5.220.0060.00814.36
5.5.210.0000.01314.44
5.5.200.0080.00014.46
5.5.190.0040.01214.09
5.5.180.0040.01114.48
5.5.170.0070.01014.48
5.5.160.0070.01014.36
5.5.150.0110.00714.59
5.5.140.0100.00514.38
5.5.130.0130.00614.41
5.5.120.0080.00314.64
5.5.110.0060.00614.05
5.5.100.0070.00314.02
5.5.90.0100.00314.41
5.5.80.0070.00714.68
5.5.70.0080.00314.31
5.5.60.0030.00714.25
5.5.50.0000.01314.46
5.5.40.0030.00614.21
5.5.30.0040.00414.64
5.5.20.0030.00914.64
5.5.10.0110.00414.47
5.5.00.0090.00614.28
5.4.450.0190.02615.34
5.4.440.0170.03015.33
5.4.430.0180.02715.31
5.4.420.0200.03315.16
5.4.410.0090.02315.29
5.4.400.0120.02015.28
5.4.390.0120.02215.18
5.4.380.0160.02215.23
5.4.370.0070.02515.30
5.4.360.0110.02314.98
5.4.350.0120.02315.31
5.4.340.0160.01715.14
5.4.330.0070.00711.07
5.4.320.0140.01915.26
5.4.310.0110.02315.12
5.4.300.0160.01615.09
5.4.290.0120.02115.09
5.4.280.0100.03015.05
5.4.270.0150.01814.96
5.4.260.0170.01715.01
5.4.250.0100.03015.01
5.4.240.0110.02115.17
5.4.230.0120.02515.11
5.4.220.0170.02514.87
5.4.210.0180.03215.00
5.4.200.0170.03815.25
5.4.190.0150.04015.21
5.4.180.0120.03015.04
5.4.170.0180.02515.18
5.4.160.0130.02614.98
5.4.150.0120.02315.18
5.4.140.0200.03813.99
5.4.130.0180.03313.74
5.4.120.0200.02813.97
5.4.110.0170.01813.78
5.4.100.0310.02713.71
5.4.90.0180.02813.75
5.4.80.0140.02413.57
5.4.70.0190.02013.91
5.4.60.0160.01813.82
5.4.50.0150.02213.84
5.4.40.0150.04013.80
5.4.30.0200.02814.00
5.4.20.0130.03913.80
5.4.10.0240.03413.90
5.4.00.0150.03513.62
5.3.290.0200.04314.77
5.3.280.0200.03314.70
5.3.270.0330.05714.76
5.3.260.0370.05714.52
5.3.250.0330.05714.57
5.3.240.0400.04714.59
5.3.230.0300.07314.81
5.3.220.0270.04014.78
5.3.210.0300.04714.46
5.3.200.0300.04014.47
5.3.190.0330.04314.61
5.3.180.0370.02714.55
5.3.170.0270.06714.63
5.3.160.0230.04314.54
5.3.150.0300.04714.59
5.3.140.0300.05714.52
5.3.130.0300.07714.54
5.3.120.0370.04714.70
5.3.110.0330.07014.76
5.3.100.0270.06713.93
5.3.90.0300.04314.01
5.3.80.0370.05714.02
5.3.70.0330.05714.13
5.3.60.0330.04713.91
5.3.50.0330.06013.92
5.3.40.0230.06314.10
5.3.30.0230.07313.89
5.3.20.0300.06313.68
5.3.10.0330.04713.79
5.3.00.0300.07013.54
5.2.170.0170.04312.39
5.2.160.0200.06312.39
5.2.150.0200.04312.39
5.2.140.0300.04312.39
5.2.130.0230.04312.39
5.2.120.0330.04712.39
5.2.110.0200.06012.39
5.2.100.0270.03012.39
5.2.90.0270.04012.39
5.2.80.0230.04712.39
5.2.70.0270.05312.39
5.2.60.0270.05312.39
5.2.50.0230.05312.39
5.2.40.0170.04712.39
5.2.30.0200.06012.39
5.2.20.0200.03012.39
5.2.10.0230.06012.39
5.2.00.0330.04012.39
5.1.60.0200.03312.39
5.1.50.0200.05312.39
5.1.40.0200.05012.39
5.1.30.0200.05012.39
5.1.20.0170.05712.39
5.1.10.0170.04312.39
5.1.00.0230.05012.39
5.0.50.0100.04312.39
5.0.40.0070.04012.39
5.0.30.0170.05312.39
5.0.20.0100.04712.39
5.0.10.0200.02712.39
5.0.00.0170.06012.39
4.4.90.0100.03712.39
4.4.80.0130.03012.39
4.4.70.0070.03712.39
4.4.60.0100.02012.39
4.4.50.0100.03712.39
4.4.40.0100.04712.39
4.4.30.0170.02712.39
4.4.20.0100.03712.39
4.4.10.0100.03012.39
4.4.00.0100.05712.39
4.3.110.0130.02312.39
4.3.100.0130.02312.39
4.3.90.0100.03012.39
4.3.80.0130.05012.39
4.3.70.0130.03012.39
4.3.60.0130.02712.39
4.3.50.0130.02712.39
4.3.40.0070.04012.39
4.3.30.0030.02312.39
4.3.20.0100.01712.39
4.3.10.0070.02012.39
4.3.00.0000.02712.39

preferences:
41.24 ms | 401 KiB | 5 Q