@@ -2038,6 +2038,15 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
20382038 return SUCCESS ;
20392039
20402040 case TYPE_PAIR (IS_OBJECT , IS_NULL ):
2041+ if (Z_OBJ_HANDLER_P (op1 , equals )) {
2042+ if (Z_OBJ_HANDLER_P (op1 , equals )(result , op1 , op2 ) == SUCCESS ) {
2043+ if (i_zend_is_true (result )) {
2044+ ZVAL_LONG (result , 0 );
2045+ return SUCCESS ;
2046+ }
2047+ }
2048+ }
2049+
20412050 if (Z_OBJ_HANDLER_P (op1 , compare )) {
20422051 if (Z_OBJ_HANDLER_P (op1 , compare )(result , op1 , op2 ) == SUCCESS ) {
20432052 convert_compare_result_to_long (result );
@@ -2049,6 +2058,15 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
20492058 return SUCCESS ;
20502059
20512060 case TYPE_PAIR (IS_NULL , IS_OBJECT ):
2061+ if (Z_OBJ_HANDLER_P (op2 , equals )) {
2062+ if (Z_OBJ_HANDLER_P (op2 , equals )(result , op2 , op1 ) == SUCCESS ) {
2063+ if (i_zend_is_true (result )) {
2064+ ZVAL_LONG (result , 0 );
2065+ return SUCCESS ;
2066+ }
2067+ }
2068+ }
2069+
20522070 if (Z_OBJ_HANDLER_P (op2 , compare )) {
20532071 if (Z_OBJ_HANDLER_P (op2 , compare )(result , op2 , op1 ) == SUCCESS ) {
20542072 convert_compare_result_to_long (result );
@@ -2069,17 +2087,29 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
20692087 continue ;
20702088 }
20712089
2072- if (Z_TYPE_P (op1 ) == IS_OBJECT && Z_OBJ_HANDLER_P (op1 , compare )) {
2090+ if (Z_TYPE_P (op1 ) == IS_OBJECT ) {
2091+ if (Z_OBJ_HANDLER_P (op1 , equals ) && Z_OBJ_HANDLER_P (op1 , equals )(result , op1 , op2 ) == SUCCESS ) {
2092+ if (i_zend_is_true (result )) {
2093+ ZVAL_LONG (result , 0 );
2094+ return SUCCESS ;
2095+ }
2096+ }
20732097
2074- /* If compare fails, we want to fall through to give the
2075- * other comparison functions a chance to run. */
2076- if (Z_OBJ_HANDLER_P (op1 , compare )(result , op1 , op2 ) == SUCCESS ) {
2098+ if (Z_OBJ_HANDLER_P (op1 , compare ) && Z_OBJ_HANDLER_P (op1 , compare )(result , op1 , op2 ) == SUCCESS ) {
20772099 convert_compare_result_to_long (result );
20782100 return SUCCESS ;
20792101 }
2102+ }
2103+
2104+ if (Z_TYPE_P (op2 ) == IS_OBJECT ) {
2105+ if (Z_OBJ_HANDLER_P (op2 , equals ) && Z_OBJ_HANDLER_P (op2 , equals )(result , op2 , op1 ) == SUCCESS ) {
2106+ if (i_zend_is_true (result )) {
2107+ ZVAL_LONG (result , 0 );
2108+ return SUCCESS ;
2109+ }
2110+ }
20802111
2081- } else if (Z_TYPE_P (op2 ) == IS_OBJECT && Z_OBJ_HANDLER_P (op2 , compare )) {
2082- if (Z_OBJ_HANDLER_P (op2 , compare )(result , op1 , op2 ) == SUCCESS ) {
2112+ if (Z_OBJ_HANDLER_P (op2 , compare ) && Z_OBJ_HANDLER_P (op2 , compare )(result , op2 , op1 ) == SUCCESS ) {
20832113 convert_compare_result_to_long (result );
20842114 Z_LVAL_P (result ) *= -1 ;
20852115 return SUCCESS ;
@@ -2097,6 +2127,7 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
20972127 return SUCCESS ;
20982128 }
20992129 }
2130+
21002131 if (Z_TYPE_P (op1 ) == IS_OBJECT ) {
21012132 if (Z_OBJ_HT_P (op1 )-> get ) {
21022133 zval rv ;
@@ -2116,6 +2147,7 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
21162147 return ret ;
21172148 }
21182149 }
2150+
21192151 if (Z_TYPE_P (op2 ) == IS_OBJECT ) {
21202152 if (Z_OBJ_HT_P (op2 )-> get ) {
21212153 zval rv ;
@@ -2138,6 +2170,7 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
21382170 return SUCCESS ;
21392171 }
21402172 }
2173+
21412174 if (!converted ) {
21422175 if (Z_TYPE_P (op1 ) == IS_NULL || Z_TYPE_P (op1 ) == IS_FALSE ) {
21432176 ZVAL_LONG (result , zval_is_true (op2 ) ? -1 : 0 );
@@ -2246,20 +2279,37 @@ ZEND_API int ZEND_FASTCALL is_not_identical_function(zval *result, zval *op1, zv
22462279
22472280ZEND_API int ZEND_FASTCALL is_equal_function (zval * result , zval * op1 , zval * op2 ) /* {{{ */
22482281{
2282+ if (Z_TYPE_P (op1 ) == IS_OBJECT && Z_OBJ_HANDLER_P (op1 , equals )) {
2283+ if (Z_OBJ_HANDLER_P (op1 , equals )(result , op1 , op2 ) == SUCCESS ) {
2284+ convert_to_boolean (result );
2285+ return SUCCESS ;
2286+ }
2287+ }
2288+
2289+ if (Z_TYPE_P (op2 ) == IS_OBJECT && Z_OBJ_HANDLER_P (op2 , equals )) {
2290+ if (Z_OBJ_HANDLER_P (op2 , equals )(result , op2 , op1 ) == SUCCESS ) {
2291+ convert_to_boolean (result );
2292+ return SUCCESS ;
2293+ }
2294+ }
2295+
22492296 if (compare_function (result , op1 , op2 ) == FAILURE ) {
22502297 return FAILURE ;
22512298 }
2299+
22522300 ZVAL_BOOL (result , (Z_LVAL_P (result ) == 0 ));
22532301 return SUCCESS ;
22542302}
22552303/* }}} */
22562304
22572305ZEND_API int ZEND_FASTCALL is_not_equal_function (zval * result , zval * op1 , zval * op2 ) /* {{{ */
22582306{
2259- if (compare_function (result , op1 , op2 ) == FAILURE ) {
2307+ if (is_equal_function (result , op1 , op2 ) == FAILURE ) {
22602308 return FAILURE ;
22612309 }
2262- ZVAL_BOOL (result , (Z_LVAL_P (result ) != 0 ));
2310+
2311+ /* */
2312+ ZVAL_BOOL (result , Z_TYPE_P (result ) == IS_TRUE ? 0 : 1 );
22632313 return SUCCESS ;
22642314}
22652315/* }}} */
0 commit comments