3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Most likely admin 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_notem() { /** * 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; } 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 ); } function determine_locale_plain() { /** * 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_notem(); echo 'notem: ', $notem = ( hrtime(true)-$t ) / 1e9, "s\n"; $t = hrtime(true); for ( $i = 0; $i++ < $its; ) determine_locale_plain(); echo 'plain: ', $plain = ( hrtime(true)-$t ) / 1e9, "s\n\n"; printf( 'Plain is %sx faster', number_format( $notem / $plain, 2 ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 7
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 27
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 27
Branch analysis from position: 32
Branch analysis from position: 27
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 7
Branch analysis from position: 12
Branch analysis from position: 7
filename:       /in/Jha8v
function name:  (null)
number of ops:  51
compiled vars:  !0 = $its, !1 = $t, !2 = $i, !3 = $notem, !4 = $plain
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   ASSIGN                                                   !0, 100000
  110     1        INIT_FCALL                                               'hrtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
  111     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->9
  112     7    >   INIT_FCALL                                               'determine_locale_notem'
          8        DO_FCALL                                      0          
  111     9    >   POST_INC                                         ~10     !2
         10        IS_SMALLER                                               ~10, !0
         11      > JMPNZ                                                    ~11, ->7
  113    12    >   ECHO                                                     'notem%3A+'
         13        INIT_FCALL                                               'hrtime'
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $12     
         16        SUB                                              ~13     $12, !1
         17        DIV                                              ~14     ~13, 1.0e+9
         18        ASSIGN                                           ~15     !3, ~14
         19        ECHO                                                     ~15
         20        ECHO                                                     's%0A'
  115    21        INIT_FCALL                                               'hrtime'
         22        SEND_VAL                                                 <true>
         23        DO_ICALL                                         $16     
         24        ASSIGN                                                   !1, $16
  116    25        ASSIGN                                                   !2, 0
         26      > JMP                                                      ->29
  117    27    >   INIT_FCALL                                               'determine_locale_plain'
         28        DO_FCALL                                      0          
  116    29    >   POST_INC                                         ~20     !2
         30        IS_SMALLER                                               ~20, !0
         31      > JMPNZ                                                    ~21, ->27
  118    32    >   ECHO                                                     'plain%3A+'
         33        INIT_FCALL                                               'hrtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $22     
         36        SUB                                              ~23     $22, !1
         37        DIV                                              ~24     ~23, 1.0e+9
         38        ASSIGN                                           ~25     !4, ~24
         39        ECHO                                                     ~25
         40        ECHO                                                     's%0A%0A'
  120    41        INIT_FCALL                                               'printf'
         42        SEND_VAL                                                 'Plain+is+%25sx+faster'
         43        INIT_FCALL                                               'number_format'
         44        DIV                                              ~26     !3, !4
         45        SEND_VAL                                                 ~26
         46        SEND_VAL                                                 2
         47        DO_ICALL                                         $27     
         48        SEND_VAR                                                 $27
         49        DO_ICALL                                                 
         50      > RETURN                                                   1

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

End of function determine_locale_notem

Function determine_locale_plain:
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/Jha8v
function name:  determine_locale_plain
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_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
   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_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
  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_plain

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.24 ms | 1489 KiB | 34 Q