@@ -1573,8 +1573,21 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
1573
1573
if (Z_TYPE_P (o1 ) == IS_OBJECT ) {
1574
1574
ZEND_ASSERT (Z_TYPE_P (o2 ) != IS_OBJECT );
1575
1575
if (Z_OBJ_HT_P (o1 )-> cast_object ) {
1576
- if (Z_OBJ_HT_P (o1 )-> cast_object (Z_OBJ_P (o1 ), & casted , ((Z_TYPE_P (o2 ) == IS_FALSE || Z_TYPE_P (o2 ) == IS_TRUE ) ? _IS_BOOL : Z_TYPE_P (o2 ))) == FAILURE ) {
1577
- return 1 ;
1576
+ zend_uchar target_type = (Z_TYPE_P (o2 ) == IS_FALSE || Z_TYPE_P (o2 ) == IS_TRUE )
1577
+ ? _IS_BOOL : Z_TYPE_P (o2 );
1578
+ if (Z_OBJ_HT_P (o1 )-> cast_object (Z_OBJ_P (o1 ), & casted , target_type ) == FAILURE ) {
1579
+ // TODO: Less crazy.
1580
+ if (target_type == IS_LONG || target_type == IS_DOUBLE ) {
1581
+ zend_error (E_NOTICE , "Object of class %s could not be converted to %s" ,
1582
+ ZSTR_VAL (Z_OBJCE_P (o1 )-> name ), zend_get_type_by_const (target_type ));
1583
+ if (target_type == IS_LONG ) {
1584
+ ZVAL_LONG (& casted , 1 );
1585
+ } else {
1586
+ ZVAL_DOUBLE (& casted , 1.0 );
1587
+ }
1588
+ } else {
1589
+ return 1 ;
1590
+ }
1578
1591
}
1579
1592
int ret = zend_compare (& casted , o2 );
1580
1593
zval_ptr_dtor (& casted );
@@ -1583,8 +1596,21 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
1583
1596
} else {
1584
1597
ZEND_ASSERT (Z_TYPE_P (o2 ) == IS_OBJECT );
1585
1598
if (Z_OBJ_HT_P (o2 )-> cast_object ) {
1586
- if (Z_OBJ_HT_P (o2 )-> cast_object (Z_OBJ_P (o2 ), & casted , ((Z_TYPE_P (o1 ) == IS_FALSE || Z_TYPE_P (o1 ) == IS_TRUE ) ? _IS_BOOL : Z_TYPE_P (o1 ))) == FAILURE ) {
1587
- return -1 ;
1599
+ zend_uchar target_type = (Z_TYPE_P (o1 ) == IS_FALSE || Z_TYPE_P (o1 ) == IS_TRUE )
1600
+ ? _IS_BOOL : Z_TYPE_P (o1 );
1601
+ if (Z_OBJ_HT_P (o2 )-> cast_object (Z_OBJ_P (o2 ), & casted , target_type ) == FAILURE ) {
1602
+ // TODO: Less crazy.
1603
+ if (target_type == IS_LONG || target_type == IS_DOUBLE ) {
1604
+ zend_error (E_NOTICE , "Object of class %s could not be converted to %s" ,
1605
+ ZSTR_VAL (Z_OBJCE_P (o2 )-> name ), zend_get_type_by_const (target_type ));
1606
+ if (target_type == IS_LONG ) {
1607
+ ZVAL_LONG (& casted , 1 );
1608
+ } else {
1609
+ ZVAL_DOUBLE (& casted , 1.0 );
1610
+ }
1611
+ } else {
1612
+ return -1 ;
1613
+ }
1588
1614
}
1589
1615
int ret = zend_compare (o1 , & casted );
1590
1616
zval_ptr_dtor (& casted );
@@ -1773,13 +1799,11 @@ ZEND_API zend_string *zend_std_get_class_name(const zend_object *zobj) /* {{{ */
1773
1799
1774
1800
ZEND_API int zend_std_cast_object_tostring (zend_object * readobj , zval * writeobj , int type ) /* {{{ */
1775
1801
{
1776
- zval retval ;
1777
- zend_class_entry * ce ;
1778
-
1779
1802
switch (type ) {
1780
- case IS_STRING :
1781
- ce = readobj -> ce ;
1803
+ case IS_STRING : {
1804
+ zend_class_entry * ce = readobj -> ce ;
1782
1805
if (ce -> __tostring ) {
1806
+ zval retval ;
1783
1807
zend_call_method_with_0_params (readobj , ce , & ce -> __tostring , "__tostring" , & retval );
1784
1808
if (EXPECTED (Z_TYPE (retval ) == IS_STRING )) {
1785
1809
ZVAL_COPY_VALUE (writeobj , & retval );
@@ -1791,29 +1815,13 @@ ZEND_API int zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj,
1791
1815
}
1792
1816
}
1793
1817
return FAILURE ;
1818
+ }
1794
1819
case _IS_BOOL :
1795
1820
ZVAL_TRUE (writeobj );
1796
1821
return SUCCESS ;
1797
- case IS_LONG :
1798
- ce = readobj -> ce ;
1799
- zend_error (E_NOTICE , "Object of class %s could not be converted to int" , ZSTR_VAL (ce -> name ));
1800
- ZVAL_LONG (writeobj , 1 );
1801
- return SUCCESS ;
1802
- case IS_DOUBLE :
1803
- ce = readobj -> ce ;
1804
- zend_error (E_NOTICE , "Object of class %s could not be converted to float" , ZSTR_VAL (ce -> name ));
1805
- ZVAL_DOUBLE (writeobj , 1 );
1806
- return SUCCESS ;
1807
- case _IS_NUMBER :
1808
- ce = readobj -> ce ;
1809
- zend_error (E_NOTICE , "Object of class %s could not be converted to number" , ZSTR_VAL (ce -> name ));
1810
- ZVAL_LONG (writeobj , 1 );
1811
- return SUCCESS ;
1812
1822
default :
1813
- ZVAL_NULL (writeobj );
1814
- break ;
1823
+ return FAILURE ;
1815
1824
}
1816
- return FAILURE ;
1817
1825
}
1818
1826
/* }}} */
1819
1827
0 commit comments