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_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/9PsqQ
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/9PsqQ
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/9PsqQ
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/9PsqQ
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/9PsqQ
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/9PsqQ
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/9PsqQ
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 = 65
Branch analysis from position: 61
2 jumps found. (Code = 46) Position 1 = 66, Position 2 = 70
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 72
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
Branch analysis from position: 70
Branch analysis from position: 65
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 = 65
Branch analysis from position: 61
Branch analysis from position: 65
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/9PsqQ
function name:  determine_locale
number of ops:  78
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
         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, ->65
         61    >   FETCH_IS                                         ~37     'GLOBALS'
         62        ISSET_ISEMPTY_DIM_OBJ                         1  ~38     ~37, 'pagenow'
         63        BOOL_NOT                                         ~39     ~38
         64        BOOL                                             ~36     ~39
         65    > > JMPZ_EX                                          ~36     ~36, ->70
         66    >   FETCH_R                      global              ~40     'GLOBALS'
         67        FETCH_DIM_R                                      ~41     ~40, 'pagenow'
         68        IS_IDENTICAL                                     ~42     ~41, 'wp-login.php'
         69        BOOL                                             ~36     ~42
         70    > > JMPZ                                                     ~36, ->72
   58    71    >   ASSIGN                                                   !0, !1
   68    72    >   INIT_FCALL                                               'apply_filters'
         73        SEND_VAL                                                 'determine_locale'
         74        SEND_VAR                                                 !0
         75        DO_FCALL                                      0  $44     
         76      > RETURN                                                   $44
   69    77*     > 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 = 36, Position 2 = 40
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 66
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 54
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 66
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
Branch analysis from position: 66
Branch analysis from position: 40
Branch analysis from position: 30
2 jumps found. (Code = 46) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
Branch analysis from position: 40
Branch analysis from position: 24
Branch analysis from position: 20
Branch analysis from position: 25
Branch analysis from position: 8
filename:       /in/9PsqQ
function name:  determine_locale_new
number of ops:  72
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
         29      > JMP                                                      ->33
   95    30    >   INIT_FCALL                                               'get_locale'
         31        DO_FCALL                                      0  $15     
         32        ASSIGN                                                   !0, $15
   98    33    >   FETCH_IS                                         ~17     'GLOBALS'
         34        ISSET_ISEMPTY_DIM_OBJ                         0  ~18     ~17, 'pagenow'
         35      > JMPZ_EX                                          ~18     ~18, ->40
         36    >   FETCH_R                      global              ~19     'GLOBALS'
         37        FETCH_DIM_R                                      ~20     ~19, 'pagenow'
         38        IS_IDENTICAL                                     ~21     ~20, 'wp-login.php'
         39        BOOL                                             ~18     ~21
         40    > > JMPZ                                                     ~18, ->66
   99    41    >   FETCH_IS                                         ~22     '_GET'
         42        ISSET_ISEMPTY_DIM_OBJ                         1  ~23     ~22, 'wp_lang'
         43        BOOL_NOT                                         ~24     ~23
         44      > JMPZ                                                     ~24, ->54
  100    45    >   INIT_FCALL                                               'sanitize_text_field'
         46        FETCH_R                      global              ~25     '_GET'
         47        FETCH_DIM_R                                      ~26     ~25, 'wp_lang'
         48        SEND_VAL                                                 ~26
         49        DO_FCALL                                      0  $27     
         50        JMP_SET                                          ~28     $27, ->52
         51        QM_ASSIGN                                        ~28     !0
         52        ASSIGN                                                   !0, ~28
         53      > JMP                                                      ->66
  101    54    >   FETCH_IS                                         ~30     '_COOKIE'
         55        ISSET_ISEMPTY_DIM_OBJ                         1  ~31     ~30, 'wp_lang'
         56        BOOL_NOT                                         ~32     ~31
         57      > JMPZ                                                     ~32, ->66
  102    58    >   INIT_FCALL                                               'sanitize_text_field'
         59        FETCH_R                      global              ~33     '_COOKIE'
         60        FETCH_DIM_R                                      ~34     ~33, 'wp_lang'
         61        SEND_VAL                                                 ~34
         62        DO_FCALL                                      0  $35     
         63        JMP_SET                                          ~36     $35, ->65
         64        QM_ASSIGN                                        ~36     !0
         65        ASSIGN                                                   !0, ~36
  113    66    >   INIT_FCALL                                               'apply_filters'
         67        SEND_VAL                                                 'determine_locale'
         68        SEND_VAR                                                 !0
         69        DO_FCALL                                      0  $38     
         70      > RETURN                                                   $38
  114    71*     > RETURN                                                   null

End of function determine_locale_new

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.13 ms | 1423 KiB | 39 Q