@@ -856,22 +856,13 @@ static zend_type_check_status zend_check_type_slow(
856856
857857 if (!strict_types ) {
858858 /* TODO: Move coercible checks here in PHP 9 when various type coercions have been removed? */
859- /* Stringable object pass a string type check */
860- // TODO: Need to fix GMP object
861- if (type_mask & MAY_BE_STRING && Z_TYPE_P (arg ) == IS_OBJECT && Z_OBJCE_P (arg )-> __tostring != NULL ) {
862- return ZEND_TYPE_CHECK_MAY_COERCE ;
863- }
864859 /* Only scalar types may coerce to other scalar types */
865- if (Z_TYPE_P (arg ) > IS_STRING || Z_TYPE_P (arg ) <= IS_NULL ) {
866- return ZEND_TYPE_CHECK_INVALID ;
867- }
868-
869- if (type_mask & (MAY_BE_LONG |MAY_BE_DOUBLE |MAY_BE_STRING )) {
860+ if (type_mask & (MAY_BE_LONG |MAY_BE_DOUBLE |MAY_BE_STRING |MAY_BE_BOOL ) && Z_TYPE_P (arg ) > IS_NULL && Z_TYPE_P (arg ) <= IS_STRING ) {
870861 return ZEND_TYPE_CHECK_MAY_COERCE ;
871862 }
872-
873- /* Singleton true/false types may not be coerced into */
874- if (( type_mask & MAY_BE_BOOL ) == MAY_BE_BOOL ) {
863+ /* Stringable object pass a string type check */
864+ // TODO: Need to fix GMP and COM variant classes
865+ if (Z_TYPE_P ( arg ) == IS_OBJECT && ( type_mask & MAY_BE_STRING ) && Z_OBJCE_P ( arg ) -> __tostring != NULL ) {
875866 return ZEND_TYPE_CHECK_MAY_COERCE ;
876867 }
877868 }
@@ -964,7 +955,7 @@ static bool zend_check_type_and_coerce(
964955 return true;
965956 }
966957 if (status == ZEND_TYPE_CHECK_MAY_COERCE ) {
967- return zend_coerce_weak_scalar_type_declaration (ZEND_TYPE_PURE_MASK (* type ), arg );
958+ return zend_coerce_weak_scalar_type_declaration (ZEND_TYPE_FULL_MASK (* type ), arg );
968959 }
969960 return false;
970961}
@@ -981,7 +972,7 @@ static bool zend_check_type_and_coerce_slow(
981972 return true;
982973 }
983974 if (status == ZEND_TYPE_CHECK_MAY_COERCE ) {
984- return zend_coerce_weak_scalar_type_declaration (ZEND_TYPE_PURE_MASK (* type ), arg );
975+ return zend_coerce_weak_scalar_type_declaration (ZEND_TYPE_FULL_MASK (* type ), arg );
985976 }
986977 return false;
987978}
0 commit comments