3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Most likely front-end scenario. function is_admin() { return false; } function wp_is_json_request() { return false; } function get_locale() { return 'en_US'; } function get_user_locale() { return 'en_US'; } function apply_filters( $a, $b ) { return $b; } function sanitize_locale_name( $a ) { return $a; } function determine_locale_actual() { /** * Filters the locale for the current request prior to the default determination process. * * Using this filter allows to override the default logic, effectively short-circuiting the function. * * @since 5.0.0 * * @param string|null $locale The locale to return and short-circuit. Default null. */ $determined_locale = apply_filters( 'pre_determine_locale', null ); if ( $determined_locale && is_string( $determined_locale ) ) { return $determined_locale; } if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] && ( ! empty( $_GET['wp_lang'] ) || ! empty( $_COOKIE['wp_lang'] ) ) ) { if ( ! empty( $_GET['wp_lang'] ) ) { $determined_locale = sanitize_locale_name( $_GET['wp_lang'] ); } else { $determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] ); } } else if ( ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) || is_admin() ) { $determined_locale = get_user_locale(); } else { $determined_locale = get_locale(); } /** * Filters the locale for the current request. * * @since 5.0.0 * * @param string $locale The locale. */ return apply_filters( 'determine_locale', $determined_locale ); } function determine_locale_proposed() { /** * Filters the locale for the current request prior to the default determination process. * * Using this filter allows to override the default logic, effectively short-circuiting the function. * * @since 5.0.0 * * @param string|null $locale The locale to return and short-circuit. Default null. */ $determined_locale = apply_filters( 'pre_determine_locale', null ); if ( $determined_locale && is_string( $determined_locale ) ) { return $determined_locale; } if ( is_admin() || ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) ) { $determined_locale = get_user_locale(); } else { $determined_locale = get_locale(); } if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { if ( ! empty( $_GET['wp_lang'] ) ) { $determined_locale = sanitize_locale_name( $_GET['wp_lang'] ) ?: $determined_locale; } elseif ( ! empty( $_COOKIE['wp_lang'] ) ) { $determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] ) ?: $determined_locale; } } /** * Filters the locale for the current request. * * @since 5.0.0 * * @param string $locale The locale. */ return apply_filters( 'determine_locale', $determined_locale ); } determine_locale_actual(); determine_locale_proposed(); $its = 1e5; $t = hrtime(true); for ( $i = 0; $i++ < $its; ) determine_locale_actual(); echo 'current: ', $old = ( hrtime(true)-$t ) / 1e9, "s\n"; $t = hrtime(true); for ( $i = 0; $i++ < $its; ) determine_locale_proposed(); echo 'proposed: ', $new = ( hrtime(true)-$t ) / 1e9, "s\n\n"; printf( 'Proposed is %sx faster', number_format( $old / $new, 2 ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 11
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 31
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 31
Branch analysis from position: 36
Branch analysis from position: 31
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 11
Branch analysis from position: 16
Branch analysis from position: 11
filename:       /in/JM0l4
function name:  (null)
number of ops:  55
compiled vars:  !0 = $its, !1 = $t, !2 = $i, !3 = $old, !4 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   INIT_FCALL                                               'determine_locale_actual'
          1        DO_FCALL                                      0          
  110     2        INIT_FCALL                                               'determine_locale_proposed'
          3        DO_FCALL                                      0          
  112     4        ASSIGN                                                   !0, 100000
  113     5        INIT_FCALL                                               'hrtime'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !1, $8
  114     9        ASSIGN                                                   !2, 0
         10      > JMP                                                      ->13
  115    11    >   INIT_FCALL                                               'determine_locale_actual'
         12        DO_FCALL                                      0          
  114    13    >   POST_INC                                         ~12     !2
         14        IS_SMALLER                                               ~12, !0
         15      > JMPNZ                                                    ~13, ->11
  116    16    >   ECHO                                                     'current%3A++'
         17        INIT_FCALL                                               'hrtime'
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $14     
         20        SUB                                              ~15     $14, !1
         21        DIV                                              ~16     ~15, 1.0e+9
         22        ASSIGN                                           ~17     !3, ~16
         23        ECHO                                                     ~17
         24        ECHO                                                     's%0A'
  118    25        INIT_FCALL                                               'hrtime'
         26        SEND_VAL                                                 <true>
         27        DO_ICALL                                         $18     
         28        ASSIGN                                                   !1, $18
  119    29        ASSIGN                                                   !2, 0
         30      > JMP                                                      ->33
  120    31    >   INIT_FCALL                                               'determine_locale_proposed'
         32        DO_FCALL                                      0          
  119    33    >   POST_INC                                         ~22     !2
         34        IS_SMALLER                                               ~22, !0
         35      > JMPNZ                                                    ~23, ->31
  121    36    >   ECHO                                                     'proposed%3A+'
         37        INIT_FCALL                                               'hrtime'
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $24     
         40        SUB                                              ~25     $24, !1
         41        DIV                                              ~26     ~25, 1.0e+9
         42        ASSIGN                                           ~27     !4, ~26
         43        ECHO                                                     ~27
         44        ECHO                                                     's%0A%0A'
  123    45        INIT_FCALL                                               'printf'
         46        SEND_VAL                                                 'Proposed+is+%25sx+faster'
         47        INIT_FCALL                                               'number_format'
         48        DIV                                              ~28     !3, !4
         49        SEND_VAL                                                 ~28
         50        SEND_VAL                                                 2
         51        DO_ICALL                                         $29     
         52        SEND_VAR                                                 $29
         53        DO_ICALL                                                 
         54      > RETURN                                                   1

Function is_admin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JM0l4
function name:  is_admin
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                   <false>
    5     1*     > RETURN                                                   null

End of function is_admin

Function wp_is_json_request:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JM0l4
function name:  wp_is_json_request
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E > > RETURN                                                   <false>
    8     1*     > RETURN                                                   null

End of function wp_is_json_request

Function get_locale:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JM0l4
function name:  get_locale
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E > > RETURN                                                   'en_US'
   12     1*     > RETURN                                                   null

End of function get_locale

Function get_user_locale:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JM0l4
function name:  get_user_locale
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E > > RETURN                                                   'en_US'
   15     1*     > RETURN                                                   null

End of function get_user_locale

Function apply_filters:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JM0l4
function name:  apply_filters
number of ops:  4
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2      > RETURN                                                   !1
   18     3*     > RETURN                                                   null

End of function apply_filters

Function sanitize_locale_name:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JM0l4
function name:  sanitize_locale_name
number of ops:  3
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1      > RETURN                                                   !0
   21     2*     > RETURN                                                   null

End of function sanitize_locale_name

Function determine_locale_actual:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
2 jumps found. (Code = 47) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 44
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 37
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 44
2 jumps found. (Code = 46) Position 1 = 47, Position 2 = 51
Branch analysis from position: 47
2 jumps found. (Code = 46) Position 1 = 52, Position 2 = 55
Branch analysis from position: 52
2 jumps found. (Code = 47) Position 1 = 56, Position 2 = 59
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 64
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 55
Branch analysis from position: 51
Branch analysis from position: 24
Branch analysis from position: 25
Branch analysis from position: 15
Branch analysis from position: 8
filename:       /in/JM0l4
function name:  determine_locale_actual
number of ops:  73
compiled vars:  !0 = $determined_locale
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'apply_filters'
          1        SEND_VAL                                                 'pre_determine_locale'
          2        SEND_VAL                                                 null
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   35     5      > JMPZ_EX                                          ~3      !0, ->8
          6    >   TYPE_CHECK                                   64  ~4      !0
          7        BOOL                                             ~3      ~4
          8    > > JMPZ                                                     ~3, ->10
   36     9    > > RETURN                                                   !0
   40    10    >   ISSET_ISEMPTY_VAR                             2  ~5      'pagenow'
         11      > JMPZ_EX                                          ~5      ~5, ->15
         12    >   FETCH_R                      global              ~6      'pagenow'
         13        IS_IDENTICAL                                     ~7      ~6, 'wp-login.php'
         14        BOOL                                             ~5      ~7
         15    > > JMPZ_EX                                          ~5      ~5, ->25
   41    16    >   FETCH_IS                                         ~8      '_GET'
         17        ISSET_ISEMPTY_DIM_OBJ                         1  ~9      ~8, 'wp_lang'
         18        BOOL_NOT                                         ~10     ~9
         19      > JMPNZ_EX                                         ~10     ~10, ->24
         20    >   FETCH_IS                                         ~11     '_COOKIE'
         21        ISSET_ISEMPTY_DIM_OBJ                         1  ~12     ~11, 'wp_lang'
         22        BOOL_NOT                                         ~13     ~12
         23        BOOL                                             ~10     ~13
         24    >   BOOL                                             ~5      ~10
         25    > > JMPZ                                                     ~5, ->44
   43    26    >   FETCH_IS                                         ~14     '_GET'
         27        ISSET_ISEMPTY_DIM_OBJ                         1  ~15     ~14, 'wp_lang'
         28        BOOL_NOT                                         ~16     ~15
         29      > JMPZ                                                     ~16, ->37
   44    30    >   INIT_FCALL                                               'sanitize_locale_name'
         31        FETCH_R                      global              ~17     '_GET'
         32        FETCH_DIM_R                                      ~18     ~17, 'wp_lang'
         33        SEND_VAL                                                 ~18
         34        DO_FCALL                                      0  $19     
         35        ASSIGN                                                   !0, $19
   43    36      > JMP                                                      ->43
   46    37    >   INIT_FCALL                                               'sanitize_locale_name'
         38        FETCH_R                      global              ~21     '_COOKIE'
         39        FETCH_DIM_R                                      ~22     ~21, 'wp_lang'
         40        SEND_VAL                                                 ~22
         41        DO_FCALL                                      0  $23     
         42        ASSIGN                                                   !0, $23
   40    43    > > JMP                                                      ->67
   49    44    >   FETCH_IS                                         ~25     '_GET'
         45        ISSET_ISEMPTY_DIM_OBJ                         0  ~26     ~25, '_locale'
         46      > JMPZ_EX                                          ~26     ~26, ->51
         47    >   FETCH_R                      global              ~27     '_GET'
         48        FETCH_DIM_R                                      ~28     ~27, '_locale'
         49        IS_IDENTICAL                                     ~29     ~28, 'user'
         50        BOOL                                             ~26     ~29
         51    > > JMPZ_EX                                          ~26     ~26, ->55
         52    >   INIT_FCALL                                               'wp_is_json_request'
         53        DO_FCALL                                      0  $30     
         54        BOOL                                             ~26     $30
         55    > > JMPNZ_EX                                         ~26     ~26, ->59
         56    >   INIT_FCALL                                               'is_admin'
         57        DO_FCALL                                      0  $31     
         58        BOOL                                             ~26     $31
         59    > > JMPZ                                                     ~26, ->64
   51    60    >   INIT_FCALL                                               'get_user_locale'
         61        DO_FCALL                                      0  $32     
         62        ASSIGN                                                   !0, $32
   49    63      > JMP                                                      ->67
   53    64    >   INIT_FCALL                                               'get_locale'
         65        DO_FCALL                                      0  $34     
         66        ASSIGN                                                   !0, $34
   63    67    >   INIT_FCALL                                               'apply_filters'
         68        SEND_VAL                                                 'determine_locale'
         69        SEND_VAR                                                 !0
         70        DO_FCALL                                      0  $36     
         71      > RETURN                                                   $36
   64    72*     > RETURN                                                   null

End of function determine_locale_actual

Function determine_locale_proposed:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 25
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 64
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 52
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 64
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
Branch analysis from position: 64
Branch analysis from position: 38
Branch analysis from position: 30
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
Branch analysis from position: 38
Branch analysis from position: 24
Branch analysis from position: 20
Branch analysis from position: 25
Branch analysis from position: 8
filename:       /in/JM0l4
function name:  determine_locale_proposed
number of ops:  70
compiled vars:  !0 = $determined_locale
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   INIT_FCALL                                               'apply_filters'
          1        SEND_VAL                                                 'pre_determine_locale'
          2        SEND_VAL                                                 null
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   78     5      > JMPZ_EX                                          ~3      !0, ->8
          6    >   TYPE_CHECK                                   64  ~4      !0
          7        BOOL                                             ~3      ~4
          8    > > JMPZ                                                     ~3, ->10
   79     9    > > RETURN                                                   !0
   83    10    >   INIT_FCALL                                               'is_admin'
         11        DO_FCALL                                      0  $5      
         12      > JMPNZ_EX                                         ~6      $5, ->25
   84    13    >   FETCH_IS                                         ~7      '_GET'
         14        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      ~7, '_locale'
         15      > JMPZ_EX                                          ~8      ~8, ->20
         16    >   FETCH_R                      global              ~9      '_GET'
         17        FETCH_DIM_R                                      ~10     ~9, '_locale'
         18        IS_IDENTICAL                                     ~11     ~10, 'user'
         19        BOOL                                             ~8      ~11
         20    > > JMPZ_EX                                          ~8      ~8, ->24
         21    >   INIT_FCALL                                               'wp_is_json_request'
         22        DO_FCALL                                      0  $12     
         23        BOOL                                             ~8      $12
         24    >   BOOL                                             ~6      ~8
         25    > > JMPZ                                                     ~6, ->30
   86    26    >   INIT_FCALL                                               'get_user_locale'
         27        DO_FCALL                                      0  $13     
         28        ASSIGN                                                   !0, $13
   83    29      > JMP                                                      ->33
   88    30    >   INIT_FCALL                                               'get_locale'
         31        DO_FCALL                                      0  $15     
         32        ASSIGN                                                   !0, $15
   91    33    >   ISSET_ISEMPTY_VAR                             2  ~17     'pagenow'
         34      > JMPZ_EX                                          ~17     ~17, ->38
         35    >   FETCH_R                      global              ~18     'pagenow'
         36        IS_IDENTICAL                                     ~19     ~18, 'wp-login.php'
         37        BOOL                                             ~17     ~19
         38    > > JMPZ                                                     ~17, ->64
   92    39    >   FETCH_IS                                         ~20     '_GET'
         40        ISSET_ISEMPTY_DIM_OBJ                         1  ~21     ~20, 'wp_lang'
         41        BOOL_NOT                                         ~22     ~21
         42      > JMPZ                                                     ~22, ->52
   93    43    >   INIT_FCALL                                               'sanitize_locale_name'
         44        FETCH_R                      global              ~23     '_GET'
         45        FETCH_DIM_R                                      ~24     ~23, 'wp_lang'
         46        SEND_VAL                                                 ~24
         47        DO_FCALL                                      0  $25     
         48        JMP_SET                                          ~26     $25, ->50
         49        QM_ASSIGN                                        ~26     !0
         50        ASSIGN                                                   !0, ~26
   92    51      > JMP                                                      ->64
   94    52    >   FETCH_IS                                         ~28     '_COOKIE'
         53        ISSET_ISEMPTY_DIM_OBJ                         1  ~29     ~28, 'wp_lang'
         54        BOOL_NOT                                         ~30     ~29
         55      > JMPZ                                                     ~30, ->64
   95    56    >   INIT_FCALL                                               'sanitize_locale_name'
         57        FETCH_R                      global              ~31     '_COOKIE'
         58        FETCH_DIM_R                                      ~32     ~31, 'wp_lang'
         59        SEND_VAL                                                 ~32
         60        DO_FCALL                                      0  $33     
         61        JMP_SET                                          ~34     $33, ->63
         62        QM_ASSIGN                                        ~34     !0
         63        ASSIGN                                                   !0, ~34
  106    64    >   INIT_FCALL                                               'apply_filters'
         65        SEND_VAL                                                 'determine_locale'
         66        SEND_VAR                                                 !0
         67        DO_FCALL                                      0  $36     
         68      > RETURN                                                   $36
  107    69*     > RETURN                                                   null

End of function determine_locale_proposed

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.68 ms | 1455 KiB | 36 Q