I was surprised while checking the opcodes generated by a PHP script, that unlike other string functions like str_pad()
, strlen()
is not a function call like it used to (if I'm not mistaken), but has a dedicated STRLEN
opcode:
strlen($c);
str_pad($c, 2);
...
8 4 STRLEN ~7 !2
...
9 6 INIT_FCALL 'str_pad'
7 SEND_VAR !2
8 SEND_VAL 2
9 DO_ICALL
https://3v4l.org/9QJQ7/vld#output
In which PHP version was this opcode introduced? I couldn't find this information anywhere.
The STRLEN opcode was added in PHP 7.0. Here's the commit that introduced it.
There are a number of other functions which have dedicated opcodes; currently, these functions are:
is_null
,is_bool
,is_long
,is_int
,is_integer
,is_float
,is_double
,is_real
,is_string
,is_array
,is_object
,is_resource
)intval
,floatval
,doubleval
,strval
)defined
chr
andord
call_user_func
andcall_user_func_array
in_array
count
(akasizeof
)get_class
get_called_class
gettype
func_get_args
andfunc_num_args
array_slice
array_key_exists