mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
Warnings to Errors hash_equals
This commit is contained in:
parent
e18bac96b7
commit
1f863399d5
@ -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)) {
|
||||
|
@ -2,21 +2,36 @@
|
||||
Hash: hash_equals() test
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(hash_equals("same", "same"));
|
||||
var_dump(hash_equals("not1same", "not2same"));
|
||||
var_dump(hash_equals("short", "longer"));
|
||||
var_dump(hash_equals("longer", "short"));
|
||||
var_dump(hash_equals("", "notempty"));
|
||||
var_dump(hash_equals("notempty", ""));
|
||||
var_dump(hash_equals("", ""));
|
||||
var_dump(hash_equals(123, "NaN"));
|
||||
var_dump(hash_equals("NaN", 123));
|
||||
var_dump(hash_equals(123, 123));
|
||||
var_dump(hash_equals(null, ""));
|
||||
var_dump(hash_equals(null, 123));
|
||||
var_dump(hash_equals(null, null));
|
||||
|
||||
function trycatch_dump(...$tests) {
|
||||
foreach ($tests as $test) {
|
||||
try {
|
||||
var_dump($test());
|
||||
}
|
||||
catch (\Error $e) {
|
||||
echo '[' . get_class($e) . '] ' . $e->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
|
||||
|
Loading…
Reference in New Issue
Block a user