PHP Kernel Tour Series
PHP Kernel Tour-1. Life cycle
PHP Kernel Tour -2.sapi CLI
PHP Kernel Tour-3. Variables
PHP Kernel Tour-4. String
First, the string source code
Zend_string
1typedefstruct_zend_string zend_string;//Defining zend_string Variables2 struct_zend_string {//_zend_string Structural Body3 Zend_refcounted_h GC;4Zend_ulong h;/*Hash Value*/5 size_t Len;6 Charval[1];7};
|
Variable |
Describe |
| 1 |
Gc |
Variable reference count information, memory management will use the |
| 2 |
H |
Harh code, the string is computed by the TIMES33 algorithm. |
| 3 |
Len |
The length of the string |
| 4 |
VAL[1] |
The contents of the string |
Second, the string structure
Attention:
1. zend_string = reference count + String hash code + string length + string content.
2. The string Val is a mutable array, and val[1] means that the string terminator is held by default.
3. Val[0] Stores an empty string. When the string is not empty, val[0 ~ Len] holds the string contents. Val[len+1] = ' 0\ '
For example, the ' test ' string is stored in this way:
Val[0] = ' t '
VAL[1] = ' e '
VAL[2] = ' s '
Val[3] = ' t '
VAL[4] = ' + ' string terminator
PHP Kernel Tour-4. Variable-length strings