這一切似乎都回到this is_numeric_string_ex
C function。
要在the implementation of ==
開始:
ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2) {
...
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
...
case TYPE_PAIR(IS_STRING, IS_STRING):
...
ZVAL_LONG(result, zendi_smart_strcmp(op1, op2));
如果兩個操作數是一個字符串,它最終調用zendi_smart_strcmp
...
ZEND_API zend_long ZEND_FASTCALL zendi_smart_strcmp(zval *s1, zval *s2) {
...
if ((ret1 = is_numeric_string_ex(Z_STRVAL_P(s1), Z_STRLEN_P(s1), &lval1, &dval1, 0, &oflow1)) &&
(ret2 = is_numeric_string_ex(Z_STRVAL_P(s2), Z_STRLEN_P(s2), &lval2, &dval2, 0, &oflow2))) ...
其中要求is_numeric_string_ex
...
/* Skip any whitespace
* This is much faster than the isspace() function */
while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r' || *str == '\v' || *str == '\f') {
str++;
length--;
}
ptr = str;
它有明確的代碼在開頭跳過空格,但不是最後。
Here http://php.net/manual/fr/language.operators.comparison.php在arnapou網點查看來自arnaud的答案。這非常好 – Hearner
非常感謝@Hearner,但是在發佈問題之前,我已經閱讀了它。 :)我只是想知道爲什麼'78'被認爲是「數字串」並且空間被忽略,但在'78'中它被考慮在內。 – Faery
在兩者上執行'var_dump();'和/或'print_r();'並查看顯示內容。這可以解釋它本身。 –