3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Most likely front-end scenario. function is_admin() { return true; } 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_text_field( $a ) { return $a; } function determine_locale() { /** * 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 ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) { return $determined_locale; } $determined_locale = get_locale(); if ( is_admin() ) { $determined_locale = get_user_locale(); } if ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) { $determined_locale = get_user_locale(); } $wp_lang = ''; if ( ! empty( $_GET['wp_lang'] ) ) { $wp_lang = sanitize_text_field( $_GET['wp_lang'] ); } elseif ( ! empty( $_COOKIE['wp_lang'] ) ) { $wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] ); } if ( ! empty( $wp_lang ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { $determined_locale = $wp_lang; } /** * 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(); function determine_locale_new() { /** * 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_text_field( $_GET['wp_lang'] ) ?: $determined_locale; } elseif ( ! empty( $_COOKIE['wp_lang'] ) ) { $determined_locale = sanitize_text_field( $_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 ); } $its = 1e5; $t = hrtime(true); for ( $i = 0; $i++ < $its; ) determine_locale(); echo 'old: ', $old = ( hrtime(true)-$t ) / 1e9, "s\n"; $t = hrtime(true); for ( $i = 0; $i++ < $its; ) determine_locale_new(); echo 'new: ', $new = ( hrtime(true)-$t ) / 1e9, "s\n\n"; printf( 'New is %sx faster', number_format( $old / $new, 2 ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 9
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 29
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 29
Branch analysis from position: 34
Branch analysis from position: 29
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 9
Branch analysis from position: 14
Branch analysis from position: 9
filename:       /in/NNkoU
function name:  (null)
number of ops:  53
compiled vars:  !0 = $its, !1 = $t, !2 = $i, !3 = $old, !4 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   INIT_FCALL                                               'determine_locale'
          1        DO_FCALL                                      0          
  116     2        ASSIGN                                                   !0, 100000
  117     3        INIT_FCALL                                               'hrtime'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !1, $7
  118     7        ASSIGN                                                   !2, 0
          8      > JMP                                                      ->11
  119     9    >   INIT_FCALL                                               'determine_locale'
         10        DO_FCALL                                      0          
  118    11    >   POST_INC                                         ~11     !2
         12        IS_SMALLER                                               ~11, !0
         13      > JMPNZ                                                    ~12, ->9
  120    14    >   ECHO                                                     'old%3A+'
         15        INIT_FCALL                                               'hrtime'
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $13     
         18        SUB                                              ~14     $13, !1
         19        DIV                                              ~15     ~14, 1.0e+9
         20        ASSIGN                                           ~16     !3, ~15
         21        ECHO                                                     ~16
         22        ECHO                                                     's%0A'
  122    23        INIT_FCALL                                               'hrtime'
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $17     
         26        ASSIGN                                                   !1, $17
  123    27        ASSIGN                                                   !2, 0
         28      > JMP                                                      ->31
  124    29    >   INIT_FCALL                                               'determine_locale_new'
         30        DO_FCALL                                      0          
  123    31    >   POST_INC                                         ~21     !2
         32        IS_SMALLER                                               ~21, !0
         33      > JMPNZ                                                    ~22, ->29
  125    34    >   ECHO                                                     'new%3A+'
         35        INIT_FCALL                                               'hrtime'
         36        SEND_VAL                                                 <true>
         37        DO_ICALL                                         $23     
         38        SUB                                              ~24     $23, !1
         39        DIV                                              ~25     ~24, 1.0e+9
         40        ASSIGN                                           ~26     !4, ~25
         41        ECHO                                                     ~26
         42        ECHO                                                     's%0A%0A'
  127    43        INIT_FCALL                                               'printf'
         44        SEND_VAL                                                 'New+is+%25sx+faster'
         45        INIT_FCALL                                               'number_format'
         46        DIV                                              ~27     !3, !4
         47        SEND_VAL                                                 ~27
         48        SEND_VAL                                                 2
         49        DO_ICALL                                         $28     
         50        SEND_VAR                                                 $28
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Function is_admin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNkoU
function name:  is_admin
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                   <true>
    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/NNkoU
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/NNkoU
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/NNkoU
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/NNkoU
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_text_field:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNkoU
function name:  sanitize_text_field
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_text_field

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

End of function determine_locale

Function determine_locale_new:
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/NNkoU
function name:  determine_locale_new
number of ops:  70
compiled vars:  !0 = $determined_locale
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     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
   85     5      > JMPZ_EX                                          ~3      !0, ->8
          6    >   TYPE_CHECK                                   64  ~4      !0
          7        BOOL                                             ~3      ~4
          8    > > JMPZ                                                     ~3, ->10
   86     9    > > RETURN                                                   !0
   90    10    >   INIT_FCALL                                               'is_admin'
         11        DO_FCALL                                      0  $5      
         12      > JMPNZ_EX                                         ~6      $5, ->25
   91    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
   93    26    >   INIT_FCALL                                               'get_user_locale'
         27        DO_FCALL                                      0  $13     
         28        ASSIGN                                                   !0, $13
   90    29      > JMP                                                      ->33
   95    30    >   INIT_FCALL                                               'get_locale'
         31        DO_FCALL                                      0  $15     
         32        ASSIGN                                                   !0, $15
   98    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
   99    39    >   FETCH_IS                                         ~20     '_GET'
         40        ISSET_ISEMPTY_DIM_OBJ                         1  ~21     ~20, 'wp_lang'
         41        BOOL_NOT                                         ~22     ~21
         42      > JMPZ                                                     ~22, ->52
  100    43    >   INIT_FCALL                                               'sanitize_text_field'
         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
   99    51      > JMP                                                      ->64
  101    52    >   FETCH_IS                                         ~28     '_COOKIE'
         53        ISSET_ISEMPTY_DIM_OBJ                         1  ~29     ~28, 'wp_lang'
         54        BOOL_NOT                                         ~30     ~29
         55      > JMPZ                                                     ~30, ->64
  102    56    >   INIT_FCALL                                               'sanitize_text_field'
         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
  113    64    >   INIT_FCALL                                               'apply_filters'
         65        SEND_VAL                                                 'determine_locale'
         66        SEND_VAR                                                 !0
         67        DO_FCALL                                      0  $36     
         68      > RETURN                                                   $36
  114    69*     > RETURN                                                   null

End of function determine_locale_new

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.07 ms | 1489 KiB | 36 Q