php运算符opcode 2

原创
2012/08/31 16:07
阅读数 68

2 . ===(调用is_identical_function),!==(调用is_not_identical_function -> is_identical_function )

<?php
$i = 1;
$j = 1.0;
echo $i === $j;

//opcode

line     # *  op                           fetch          ext  return  operands
---------------------------------------------------------------------------------
   3     0  >   ASSIGN                                                   !0, 1
   4     1      ASSIGN                                                   !1, 1
   6     2      IS_IDENTICAL                                     ~2      !0, !1
         3      ECHO                                                     ~2
   7     4    > RETURN                                                   1

//调用is_identical_function

 

Z_TYPE_P(result) = IS_BOOL;
    if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {//首先比较类型,如果类型不同,直接返回false
        Z_LVAL_P(result) = 0;
        return SUCCESS;
    }
    switch (Z_TYPE_P(op1)) {
        case IS_NULL:  //null
            Z_LVAL_P(result) = 1;
            break;
        case IS_BOOL:
        case IS_LONG:
        case IS_RESOURCE://bool 整形,资源
            Z_LVAL_P(result) = (Z_LVAL_P(op1) == Z_LVAL_P(op2));
            break;
        case IS_DOUBLE://double
            Z_LVAL_P(result) = (Z_DVAL_P(op1) == Z_DVAL_P(op2));
            break;
        case IS_STRING://字符串
            Z_LVAL_P(result) = ((Z_STRLEN_P(op1) == Z_STRLEN_P(op2))
                && (!memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1))));
            break;
        case IS_ARRAY://数组
            Z_LVAL_P(result) = (Z_ARRVAL_P(op1) == Z_ARRVAL_P(op2) ||
                zend_hash_compare(Z_ARRVAL_P(op1), Z_ARRVAL_P(op2), (compare_func_t) hash_zval_identical_function, 1 TSRMLS_CC)==0);
            break;
        case IS_OBJECT://对象
            if (Z_OBJ_HT_P(op1) == Z_OBJ_HT_P(op2)) {
                Z_LVAL_P(result) = (Z_OBJ_HANDLE_P(op1) == Z_OBJ_HANDLE_P(op2));
            } else {
                Z_LVAL_P(result) = 0;
            }
            break;
        default:
            Z_LVAL_P(result) = 0;
            return FAILURE;
    }
    return SUCCESS;

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部