From: Mark Date: Mon, 26 Aug 2019 22:44:20 +0000 (+0100) Subject: Warnings to Errors hash_equals X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f863399d539b1bb090c281a4b9e04209540be6b;p=php Warnings to Errors hash_equals --- diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 8a9485cb70..f968daf5ef 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -864,13 +864,13 @@ PHP_FUNCTION(hash_equals) /* We only allow comparing string to prevent unexpected results. */ if (Z_TYPE_P(known_zval) != IS_STRING) { - php_error_docref(NULL, E_WARNING, "Expected known_string to be a string, %s given", zend_zval_type_name(known_zval)); - RETURN_FALSE; + zend_type_error("Expected known_string to be a string, %s given", zend_zval_type_name(known_zval)); + return; } if (Z_TYPE_P(user_zval) != IS_STRING) { - php_error_docref(NULL, E_WARNING, "Expected user_string to be a string, %s given", zend_zval_type_name(user_zval)); - RETURN_FALSE; + zend_type_error("Expected user_string to be a string, %s given", zend_zval_type_name(user_zval)); + return; } if (Z_STRLEN_P(known_zval) != Z_STRLEN_P(user_zval)) { diff --git a/ext/hash/tests/hash_equals.phpt b/ext/hash/tests/hash_equals.phpt index 0c8ab42f93..1716d3be66 100644 --- a/ext/hash/tests/hash_equals.phpt +++ b/ext/hash/tests/hash_equals.phpt @@ -2,21 +2,36 @@ Hash: hash_equals() test --FILE-- getMessage() . "\n"; + } + } +} + +trycatch_dump( + fn() => hash_equals("same", "same"), + fn() => hash_equals("not1same", "not2same"), + fn() => hash_equals("short", "longer"), + fn() => hash_equals("longer", "short"), + fn() => hash_equals("", "notempty"), + fn() => hash_equals("notempty", ""), + fn() => hash_equals("", ""), + fn() => hash_equals(123, "NaN"), + fn() => hash_equals("NaN", 123), + fn() => hash_equals(123, 123), + fn() => hash_equals(null, ""), + fn() => hash_equals(null, 123), + fn() => hash_equals(null, null), +); + ?> ---EXPECTF-- +--EXPECT-- bool(true) bool(false) bool(false) @@ -24,21 +39,9 @@ bool(false) bool(false) bool(false) bool(true) - -Warning: hash_equals(): Expected known_string to be a string, int given in %s on line %d -bool(false) - -Warning: hash_equals(): Expected user_string to be a string, int given in %s on line %d -bool(false) - -Warning: hash_equals(): Expected known_string to be a string, int given in %s on line %d -bool(false) - -Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d -bool(false) - -Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d -bool(false) - -Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d -bool(false) +[TypeError] Expected known_string to be a string, int given +[TypeError] Expected user_string to be a string, int given +[TypeError] Expected known_string to be a string, int given +[TypeError] Expected known_string to be a string, null given +[TypeError] Expected known_string to be a string, null given +[TypeError] Expected known_string to be a string, null given