3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Plugin Name: WP doodlez * Plugin URI: https://github.com/Kolatzek/WPdoodlez * Description: Doodle like finding meeting date * Author: Robert Kolatzek * Version: 1.0.6 * Author URI: http://robert.kolatzek.org * License: GPL 2 */ /** * Translate string * @param string $text * @return string */ function wpd_translate( $text ) { return __( $text, 'WPdoodlez' ); } /** * Load plugin textdomain. */ function WPdoodlez_load_textdomain() { load_plugin_textdomain( 'WPdoodlez', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' ); } add_action( 'plugins_loaded', 'WPdoodlez_load_textdomain' ); /** * Register own template for doodles * @global post $post * @param string $single_template * @return string */ function wpdoodlez_template( $single_template ) { global $post; if ( $post->post_type == 'wpdoodle' ) { $single_template = dirname( __FILE__ ) . '/wpdoodle-template.php'; } return $single_template; } add_filter( 'single_template', 'wpdoodlez_template' ); /** * Save a single vote as ajax request and set cookie with given user name */ function wpdoodlez_save_vote() { $values = get_option( 'wpdoodlez_' . strval($_POST[ 'data' ][ 'wpdoodle' ]), array() ); $name = sanitize_text_field( $_POST[ 'data' ][ 'name' ]); /* insert only without cookie (or empty name in cookie) * update only with same name in cookie */ $nameInCookie = strval($_COOKIE[ 'wpdoodlez-' . $_POST[ 'data' ][ 'wpdoodle' ] ]); if ( (isset( $values[ $name ] ) && $nameInCookie == $name) || (!isset( $values[ $name ] ) && empty( $nameInCookie )) ) { $values[ $name ] = array(); foreach ( $_POST[ 'data' ][ 'vote' ] as $option ) { $values[ $name ][ strval($option[ 'name' ]) ] = sanitize_text_field($option[ 'value' ]); } } else { echo json_encode( array( 'save' => false , 'msg' => wpd_translate( 'You have already voted but your vote was deleted. Your name was: ' ).$nameInCookie ) ); wp_die(); } update_option( 'wpdoodlez_' . (string)$_POST[ 'data' ][ 'wpdoodle' ], $values ); setcookie( 'wpdoodlez-' . (string)$_POST[ 'data' ][ 'wpdoodle' ], $name, time() + (3600 * 24 * 30), COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); echo json_encode( array( 'save' => true ) ); wp_die(); } add_action( 'wp_ajax_wpdoodlez_save', 'wpdoodlez_save_vote' ); add_action( 'wp_ajax_nopriv_wpdoodlez_save', 'wpdoodlez_save_vote' ); /** * Delete a given vote identified by user name. Possible for all wp user with *delete_published_posts* right */ function wpdoodlez_delete_vote() { if ( !current_user_can( 'delete_published_posts' ) ) { echo json_encode( array( 'delete' => false ) ); wp_die(); } $values = get_option( 'wpdoodlez_' . (string)$_POST[ 'data' ][ 'wpdoodle' ], array() ); $newvalues = [ ]; foreach ( $values as $key => $value ) { if ( $key != (string) $_POST[ 'data' ][ 'name' ] ) { $newvalues[ $key ] = $value; } } update_option( 'wpdoodlez_' . (string)$_POST[ 'data' ][ 'wpdoodle' ], $newvalues ); echo json_encode( array( 'delete' => true ) ); wp_die(); } add_action( 'wp_ajax_nopriv_wpdoodlez_delete', 'wpdoodlez_delete_vote' ); add_action( 'wp_ajax_wpdoodlez_delete', 'wpdoodlez_delete_vote' ); /** * Register WPdoodle post type * Set cookie with the name of user (used by voting) */ function wpdoodlez_cookie() { include('wpdoodlez_post_type.php'); foreach ( $_COOKIE as $key => $value ) { if ( preg_match( '/wpdoodlez\-.+/i', (string)$key ) ) { setcookie( (string)$key, (string)$value, time() + (3600 * 24 * 30), COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); } } } add_action( 'init', 'wpdoodlez_cookie' ); /** * Register WPdoodle post type and refresh rewrite rules */ function wpdoodlez_rewrite_flush() { wpdoodlez_cookie(); flush_rewrite_rules(); } register_activation_hook( __FILE__, 'wpdoodlez_rewrite_flush' ); add_action( 'after_switch_theme', 'wpdoodlez_rewrite_flush' ); ?>

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.0.120.0040.00813.34
8.0.110.0050.00713.32
8.0.100.0100.00213.32
8.0.90.0130.00013.35
8.0.80.0090.00413.32
8.0.70.0090.00413.33
8.0.60.0060.00713.34
8.0.50.0120.00013.31
8.0.30.0060.00613.36
8.0.20.0080.00513.35
8.0.10.0000.01213.40
8.0.00.0060.00013.34
7.4.250.0100.00013.24
7.4.240.0040.00913.18
7.4.230.0100.00313.23
7.4.220.0080.00413.27
7.4.210.0080.00413.34
7.4.200.0120.00013.19
7.4.190.0070.00313.33
7.4.180.0040.00413.38
7.4.160.0000.00813.30
7.4.150.0000.00713.32
7.4.140.0030.00313.27
7.4.130.0060.00613.18
7.4.120.0040.00813.21
7.4.110.0090.00413.21
7.4.100.0120.00013.29
7.4.90.0080.00413.33
7.4.80.0060.00613.23
7.4.70.0090.00313.19
7.4.60.0070.00013.20
7.4.50.0000.00613.14
7.4.40.0060.00013.18
7.4.30.0000.00613.30
7.4.20.0020.00413.19
7.4.10.0080.00013.16
7.4.00.0000.00713.11
7.3.310.0050.00213.20
7.3.300.0040.00213.16
7.3.290.0050.00213.28
7.3.280.0080.00013.30
7.3.270.0000.00813.34
7.3.260.0040.00213.32
7.3.250.0060.00313.19
7.3.240.0080.00013.16
7.3.230.0000.00913.38
7.3.220.0080.00013.26
7.3.210.0090.00013.26
7.3.200.0090.00013.27
7.3.190.0060.00313.10
7.3.180.0030.00313.20
7.3.170.0000.00713.32
7.3.160.0000.00513.11
7.3.150.0000.00513.07
7.3.140.0000.00513.24
7.3.130.0030.00313.27
7.3.120.0030.00313.08
7.3.110.0060.00613.05
7.3.100.0090.00413.00
7.3.90.0050.00913.48
7.3.80.0090.00613.10
7.3.70.0060.00813.35
7.3.60.0090.00313.39
7.3.50.0090.00313.42
7.3.40.0090.00313.38
7.3.30.0080.00413.26
7.3.20.0120.00215.21
7.3.10.0050.01014.96
7.3.00.0140.00014.96
7.2.340.0090.00313.30
7.2.330.0100.00313.39
7.2.320.0120.00013.30
7.2.310.0100.00313.18
7.2.300.0060.00613.39
7.2.290.0000.01313.20
7.2.280.0090.00313.35
7.2.270.0000.01213.34
7.2.260.0090.00413.18
7.2.250.0120.00013.13
7.2.240.0100.00313.14
7.2.230.0080.00513.26
7.2.220.0030.00913.30
7.2.210.0090.00413.33
7.2.200.0100.00313.40
7.2.190.0070.00713.48
7.2.180.0100.00313.26
7.2.170.0060.00613.52
7.2.160.0090.00413.32
7.2.150.0030.01015.08
7.2.140.0090.00315.30
7.2.130.0130.00015.36
7.2.120.0090.00415.14
7.2.110.0090.00615.09
7.2.100.0100.00315.15
7.2.90.0100.00315.23
7.2.80.0090.00315.10
7.2.70.0130.00015.14
7.2.60.0090.00916.00
7.2.50.0050.01016.04
7.2.40.0060.00615.11
7.2.30.0080.00515.11
7.2.20.0130.00015.12
7.2.10.0140.00015.33
7.2.00.0030.01117.18
7.1.330.0070.00514.14
7.1.320.0080.00414.13
7.1.310.0110.00013.93
7.1.300.0120.00014.14
7.1.290.0130.00013.99
7.1.280.0120.00014.14
7.1.270.0080.00414.26
7.1.260.0120.00014.16
7.1.250.0040.00814.15
7.1.240.0120.00014.11
7.1.230.0120.00014.16
7.1.220.0120.00014.03
7.1.210.0100.00214.02
7.1.200.0090.00314.81
7.1.190.0060.00614.15
7.1.180.0100.00214.20
7.1.170.0100.00214.09
7.1.160.0060.00614.01
7.1.150.0090.00314.00
7.1.140.0120.00013.92
7.1.130.0060.00614.13
7.1.120.0070.00514.10
7.1.110.0120.00014.22
7.1.100.0060.00614.07
7.1.90.0120.00013.93
7.1.80.0070.00514.18
7.1.70.0030.00715.53
7.1.60.0080.00415.64
7.1.50.0100.00915.54
7.1.40.0120.00014.01
7.1.30.0130.00014.02
7.1.20.0110.00314.06
7.1.10.0060.00614.13
7.1.00.0090.03618.23
7.0.330.0110.00014.06
7.0.320.0110.00014.04
7.0.310.0120.00014.04
7.0.300.0110.00013.93
7.0.290.0080.00413.87
7.0.280.0060.00613.93
7.0.270.0110.00213.91
7.0.260.0000.01114.01
7.0.250.0120.00014.12
7.0.240.0080.00414.26
7.0.230.0080.00414.21
7.0.220.0000.01214.15
7.0.210.0120.00014.05
7.0.200.1030.00314.41
7.0.190.0070.00514.11
7.0.180.0060.00614.13
7.0.170.0040.00814.21
7.0.160.0060.00614.10
7.0.150.0080.00414.00
7.0.140.0070.00514.06
7.0.130.0100.00214.18
7.0.120.0120.00013.99
7.0.110.0120.03317.25
7.0.100.0060.03317.17
7.0.90.0170.03417.17
7.0.80.0100.04017.18
7.0.70.0110.02817.14
7.0.60.0170.03217.26
7.0.50.0090.03217.22
7.0.40.0120.03717.17
7.0.30.0350.03617.20
7.0.20.0240.03117.15
7.0.10.0150.03917.16
7.0.00.0260.03317.25
5.6.400.0040.00812.38
5.6.390.0040.00812.58
5.6.380.0080.00412.32
5.6.370.0110.00012.68
5.6.360.0040.00712.50
5.6.350.0100.00012.37
5.6.340.0070.00412.58
5.6.330.0050.00512.59
5.6.320.0110.00012.41
5.6.310.0040.00812.29
5.6.300.0040.00812.55
5.6.290.0090.00212.52
5.6.280.0120.00012.50
5.6.270.0110.00012.32
5.6.260.0160.03516.81
5.6.250.0060.03316.76
5.6.240.0120.03916.67
5.6.230.0050.04616.68
5.6.220.0100.03316.89
5.6.210.0140.02816.86
5.6.200.0060.03516.83
5.6.190.0160.03916.62
5.6.180.0150.03216.83
5.6.170.0100.03416.84
5.6.160.0140.03216.85
5.6.150.0150.03516.88
5.6.140.0120.03416.75
5.6.130.0120.02716.84
5.6.120.0100.03416.70
5.6.110.0090.03516.58
5.6.100.0130.03116.71
5.6.90.0110.03116.81
5.6.80.0140.03216.41
5.6.70.0120.02716.50
5.6.60.0110.02616.44
5.6.50.0060.03116.53
5.6.40.0020.04716.31
5.6.30.0140.02716.34
5.6.20.0100.03916.45
5.6.10.0110.03416.45
5.6.00.0130.04016.35

preferences:
41.47 ms | 400 KiB | 5 Q