Simply talk about the strlen function in PHP

Source: Internet
Author: User
Description of the Strlen function.

int strlen (String $string)

In this article, we can know that the strlen 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 (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "s", &s1, &s1_len) = = FAILURE) {    return;  }  Retval_long (S1_len);}

The article says that the function is simple and does not require further explanation. This article also has an introduction to the Zend_parse_parameters function. I am more stupid, so I would like to understand how the Zend_parse_parameters function returns the length of the variable.

In the Zend_parse_arg_impl function, where the arguments are parsed, we continue to look at the branch of case ' s '. This branch is the parsing of string variables.

int *PL = Va_arg (*va, int *); is the definition of the string length variable.

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

The Z_STRLEN_PP macro is defined in the Zend_operators.h file:

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

Continue looking at the definition of Z_strlen 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.

The above introduces a simple talk about PHP strlen function, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.