[PHP Source reading note]strlen function

Source: Internet
Author: User

Article from: Http://www.aintnot.com/2016/02/22/phps-source-analytics-strlen

Description of the Strlen function.

strlen string $string )

In this article, we can know that strlen the function is defined by the Zend engine. The definition of a function can be viewed here.

The source code for the function is also given here:

zend_function (strlen) {    char *s1;     int S1_len;     if " s ", &s1, &s1_len) = = FAILURE)        {return;    }    Retval_long (S1_len);}

The article says 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. I am more stupid, so I want to understand zend_parse_parameters how the function returns the length of the variable.

In the zend_parse_arg_impl function, which is where the argument is parsed, we continue to look at case ‘s‘ the branch. This branch is the parsing of string variables.

int *pl = va_arg(*va, int *);Is the definition of a string length variable.

Continue looking down and you can see the pl assignment statement for the variable: *pl = Z_STRLEN_PP(arg); .

and the Z_STRLEN_PP definition of the macro in the zend_operators.h file:

#define Z_STRLEN_PP (ZVAL_PP)    Z_strlen (**ZVAL_PP)

Then continue to see Z_STRLEN the definition of the macro #define Z_STRLEN(zval) (zval).value.str.len . From this we can know that the strlen function is implemented by directly returning the Len attribute of str in the Zval struct.

[PHP Source reading note]strlen function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.