Skip to content

Commit 0929595

Browse files
committed
Promote warnings to errors in extract()
1 parent 5b8e12a commit 0929595

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

ext/standard/array.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,23 +2448,24 @@ PHP_FUNCTION(extract)
24482448
extract_type &= 0xff;
24492449

24502450
if (extract_type < EXTR_OVERWRITE || extract_type > EXTR_IF_EXISTS) {
2451-
php_error_docref(NULL, E_WARNING, "Invalid extract type");
2451+
zend_throw_error(NULL, "Invalid extract type");
24522452
return;
24532453
}
24542454

24552455
if (extract_type > EXTR_SKIP && extract_type <= EXTR_PREFIX_IF_EXISTS && ZEND_NUM_ARGS() < 3) {
2456-
php_error_docref(NULL, E_WARNING, "specified extract type requires the prefix parameter");
2456+
zend_throw_error(NULL, "specified extract type requires the prefix parameter");
24572457
return;
24582458
}
24592459

24602460
if (prefix) {
24612461
if (ZSTR_LEN(prefix) && !php_valid_var_name(ZSTR_VAL(prefix), ZSTR_LEN(prefix))) {
2462-
php_error_docref(NULL, E_WARNING, "prefix is not a valid identifier");
2462+
zend_throw_error(NULL, "prefix is not a valid identifier");
24632463
return;
24642464
}
24652465
}
24662466

24672467
if (zend_forbid_dynamic_call("extract()") == FAILURE) {
2468+
/* TODO Elevate to exception ? */
24682469
return;
24692470
}
24702471

ext/standard/tests/array/extract_error.phpt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,33 @@ echo "*** Testing Error Conditions ***\n";
88

99
/* Invalid second argument ( only 0-6 is valid) */
1010
$arr = array(1);
11-
var_dump( extract($arr, -1 . "wddr") );
12-
var_dump( extract($arr, 7 , "wddr") );
11+
12+
try {
13+
var_dump( extract($arr, -1 . "wddr") );
14+
} catch (\Error $e) {
15+
echo $e->getMessage() . "\n";
16+
}
17+
18+
try {
19+
var_dump( extract($arr, 7 , "wddr") );
20+
} catch (\Error $e) {
21+
echo $e->getMessage() . "\n";
22+
}
1323

1424
/* Two Arguments, second as prefix but without prefix string as third argument */
15-
var_dump( extract($arr,EXTR_PREFIX_IF_EXISTS) );
25+
try {
26+
var_dump( extract($arr,EXTR_PREFIX_IF_EXISTS) );
27+
} catch (\Error $e) {
28+
echo $e->getMessage() . "\n";
29+
}
1630

1731
echo "Done\n";
1832
?>
1933
--EXPECTF--
2034
*** Testing Error Conditions ***
2135

2236
Notice: A non well formed numeric value encountered in %s on line %d
23-
24-
Warning: extract(): Invalid extract type in %s on line %d
25-
NULL
26-
27-
Warning: extract(): Invalid extract type in %s on line %d
28-
NULL
29-
30-
Warning: extract(): specified extract type requires the prefix parameter in %s on line %d
31-
NULL
37+
Invalid extract type
38+
Invalid extract type
39+
specified extract type requires the prefix parameter
3240
Done

0 commit comments

Comments
 (0)