@@ -857,22 +857,13 @@ static zend_type_check_status zend_check_type_slow(
857857
858858 if (!strict_types ) {
859859 /* TODO: Move coercible checks here in PHP 9 when various type coercions have been removed? */
860- /* Stringable object pass a string type check */
861- // TODO: Need to fix GMP object
862- if (type_mask & MAY_BE_STRING && Z_TYPE_P (arg ) == IS_OBJECT && Z_OBJCE_P (arg )-> __tostring != NULL ) {
863- return ZEND_TYPE_CHECK_MAY_COERCE ;
864- }
865860 /* Only scalar types may coerce to other scalar types */
866- if (Z_TYPE_P (arg ) > IS_STRING || Z_TYPE_P (arg ) <= IS_NULL ) {
867- return ZEND_TYPE_CHECK_INVALID ;
868- }
869-
870- if (type_mask & (MAY_BE_LONG |MAY_BE_DOUBLE |MAY_BE_STRING )) {
861+ 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 ) {
871862 return ZEND_TYPE_CHECK_MAY_COERCE ;
872863 }
873-
874- /* Singleton true/false types may not be coerced into */
875- if (( type_mask & MAY_BE_BOOL ) == MAY_BE_BOOL ) {
864+ /* Stringable object pass a string type check */
865+ // TODO: Need to fix GMP and COM variant classes
866+ if (Z_TYPE_P ( arg ) == IS_OBJECT && ( type_mask & MAY_BE_STRING ) && Z_OBJCE_P ( arg ) -> __tostring != NULL ) {
876867 return ZEND_TYPE_CHECK_MAY_COERCE ;
877868 }
878869 }
@@ -960,7 +951,7 @@ static bool zend_check_type_and_coerce(
960951 return true;
961952 }
962953 if (status == ZEND_TYPE_CHECK_MAY_COERCE ) {
963- return zend_coerce_weak_scalar_type_declaration (ZEND_TYPE_PURE_MASK (* type ), arg );
954+ return zend_coerce_weak_scalar_type_declaration (ZEND_TYPE_FULL_MASK (* type ), arg );
964955 }
965956 return false;
966957}
@@ -977,7 +968,7 @@ static bool zend_check_type_and_coerce_slow(
977968 return true;
978969 }
979970 if (status == ZEND_TYPE_CHECK_MAY_COERCE ) {
980- return zend_coerce_weak_scalar_type_declaration (ZEND_TYPE_PURE_MASK (* type ), arg );
971+ return zend_coerce_weak_scalar_type_declaration (ZEND_TYPE_FULL_MASK (* type ), arg );
981972 }
982973 return false;
983974}
0 commit comments