PHP String Length Without strlen()

前端 未结 3 1145
北恋
北恋 2021-01-20 03:37

Just browsing over the latest release of the PHP coding standards, and something caught my eye:

http://svn.php.net/viewvc/php/php-src/trunk/CODING_STANDARDS?revision

相关标签:
3条回答
  • 2021-01-20 04:02

    Its been clearly mentioned that they talking about PHP Coding standards not about C function or extension of PHP engines.

    ========================
    PHP Coding Standards
    ========================
    This file lists several standards that any programmer, adding or changing code in PHP, should follow. Since this file was added at a very late stage of the development of PHP v3.0, the code base does not (yet) fully follow it, but it's going in that general direction. Since we are now well into the version 4 releases, many sections have been recoded to use these rules.

    Still I didn't found any relevant information about string length property but I think in future they might release the information if it's related to new version of PHP.

    Please post if someone found useful information about this.

    0 讨论(0)
  • 2021-01-20 04:06

    To get the length of a string zval (variable in C) use Z_STRLEN(your_zval) see zend_operators.h at line 398 (PHP 5.4) :

    #define Z_STRLEN(zval)          (zval).value.str.len
    
    0 讨论(0)
  • 2021-01-20 04:12

    They're talking about the C function, not the PHP function. The C function will stop counting after the first \0, but PHP strings can contain \0 elsewhere other than the end.

    0 讨论(0)
提交回复
热议问题