Skip to content

Commit 3d3b88c

Browse files
committed
Condence weak mode type checks may coerce
1 parent 041568e commit 3d3b88c

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

Zend/zend_execute.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -959,7 +950,7 @@ static bool zend_check_type_and_coerce(
959950
return true;
960951
}
961952
if (status == ZEND_TYPE_CHECK_MAY_COERCE) {
962-
return zend_coerce_weak_scalar_type_declaration(ZEND_TYPE_PURE_MASK(*type), arg);
953+
return zend_coerce_weak_scalar_type_declaration(ZEND_TYPE_FULL_MASK(*type), arg);
963954
}
964955
return false;
965956
}
@@ -976,7 +967,7 @@ static bool zend_check_type_and_coerce_slow(
976967
return true;
977968
}
978969
if (status == ZEND_TYPE_CHECK_MAY_COERCE) {
979-
return zend_coerce_weak_scalar_type_declaration(ZEND_TYPE_PURE_MASK(*type), arg);
970+
return zend_coerce_weak_scalar_type_declaration(ZEND_TYPE_FULL_MASK(*type), arg);
980971
}
981972
return false;
982973
}

0 commit comments

Comments
 (0)