strlen function Description.
int strlen (String $string)
In this article, we can see that the strlen function is defined by the Zend engine. The definition of a function can be viewed here.
Here also gives the function of the source code:
Zend_function (strlen)
{
char *s1;
int S1_len;
if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "s", &s1, &s1_len) = = failure) {return
;
}
Retval_long (S1_len);
}
The article mentions that the function is simple and does not require further explanation. And this article also has the Zend_parse_parameters function to do the introduction. The writer is stupid, so I want to understand how the Zend_parse_parameters function returns the length of the variable.
In the Zend_parse_arg_impl function, which is the parsing parameter, we continue to look at the branch of case ' s '. This branch is a parse of a string variable.
int *PL = Va_arg (*va, int *); is the definition of the string length variable.
Looking further down, you can see the assignment statement for the PL variable: *pl = z_strlen_pp (arg);.
The definition of the Z_STRLEN_PP macro is in the Zend_operators.h file:
#define Z_STRLEN_PP (ZVAL_PP) Z_strlen (**ZVAL_PP)
Then continue to look at the definition of the Z_strlen macro, #define Z_strlen (Zval) (zval). Value.str.len. From this we can see that the strlen function is achieved by directly returning the Len attribute of str in the ZVAL structure.