Skip to content

Commit db5f85e

Browse files
committed
Cleanup argument handling of Zend functions and methods
1 parent 1c967df commit db5f85e

23 files changed

+199
-155
lines changed

Zend/tests/002.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,26 @@ try {
9696
echo "Done\n";
9797
?>
9898
--EXPECTF--
99-
func_get_arg(): Argument #1 ($arg_num) must be greater than or equal to 0
100-
func_get_arg(): Argument 0 not passed to function
101-
func_get_arg(): Argument 1 not passed to function
102-
func_get_arg(): Argument #1 ($arg_num) must be greater than or equal to 0
99+
func_get_arg(): Argument #1 ($argument_number) must be greater than or equal to 0
100+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
101+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
102+
func_get_arg(): Argument #1 ($argument_number) must be greater than or equal to 0
103103
int(10)
104-
func_get_arg(): Argument 1 not passed to function
104+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
105105
int(1)
106-
func_get_arg(): Argument 1 not passed to function
106+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
107107
Exception: Too few arguments to function test2(), 0 passed in %s002.php on line %d and exactly 1 expected
108108
int(1)
109109
int(2)
110-
func_get_arg(): Argument 2 not passed to function
111-
func_get_arg(): Argument #1 ($arg_num) must be greater than or equal to 0
112-
func_get_arg(): Argument 0 not passed to function
113-
func_get_arg(): Argument 1 not passed to function
110+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
111+
func_get_arg(): Argument #1 ($argument_number) must be greater than or equal to 0
112+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
113+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
114114
Exception: Too few arguments to function test3(), 1 passed in %s on line %d and exactly 2 expected
115115
int(1)
116116
int(2)
117-
func_get_arg(): Argument 2 not passed to function
117+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
118118
int(1)
119-
func_get_arg(): Argument 1 not passed to function
119+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
120120
func_get_arg() cannot be called from the global scope
121121
Done

Zend/tests/004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var_dump(strncmp("qwerty", "qwerty123", 7));
1616
?>
1717
--EXPECT--
1818
int(0)
19-
strncmp(): Argument #3 ($len) must be greater than or equal to 0
19+
strncmp(): Argument #3 ($length) must be greater than or equal to 0
2020
int(0)
2121
int(0)
2222
int(-1)

Zend/tests/006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var_dump(strncasecmp("01", "01", 1000));
1919

2020
?>
2121
--EXPECT--
22-
strncasecmp(): Argument #3 ($len) must be greater than or equal to 0
22+
strncasecmp(): Argument #3 ($length) must be greater than or equal to 0
2323
int(0)
2424
int(-3)
2525
int(0)

Zend/tests/008.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ var_dump(define("test const", 3));
1616
var_dump(define("test const", 3));
1717
var_dump(define("test", array(1)));
1818
var_dump(define("test1", fopen(__FILE__, 'r')));
19+
20+
try {
1921
var_dump(define("test2", new stdclass));
22+
} catch (TypeError $exception) {
23+
echo $exception->getMessage() . "\n";
24+
}
2025

2126
var_dump(constant(" "));
2227
var_dump(constant("[[["));
@@ -37,9 +42,7 @@ Notice: Constant test const already defined in %s on line %d
3742
bool(false)
3843
bool(true)
3944
bool(true)
40-
41-
Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d
42-
bool(false)
45+
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
4346
int(1)
4447
int(2)
4548
int(3)

Zend/tests/020.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ try {
2626
?>
2727
--EXPECT--
2828
func_get_arg() cannot be called from the global scope
29-
func_get_arg(): Argument 1 not passed to function
29+
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function

Zend/tests/bug37811.phpt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ class TestClass
1111
}
1212
}
1313

14-
define("Bar",new TestClass);
14+
define("Bar", new TestClass);
1515
var_dump(Bar);
16-
define("Baz",new stdClass);
17-
var_dump(Baz);
1816

19-
?>
20-
===DONE===
21-
--EXPECTF--
22-
string(3) "Foo"
17+
try {
18+
define("Baz", new stdClass);
19+
} catch (TypeError $exception) {
20+
echo $exception->getMessage() . "\n";
21+
}
2322

24-
Warning: Constants may only evaluate to scalar values, arrays or resources in %sbug37811.php on line %d
23+
try {
24+
var_dump(Baz);
25+
} catch (Error $exception) {
26+
echo $exception->getMessage() . "\n";
27+
}
2528

26-
Fatal error: Uncaught Error: Undefined constant "Baz" in %s:%d
27-
Stack trace:
28-
#0 {main}
29-
thrown in %s on line %d
29+
?>
30+
--EXPECT--
31+
string(3) "Foo"
32+
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
33+
Undefined constant "Baz"

Zend/tests/bug44827.phpt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
Bug #44827 (define() allows :: in constant names)
33
--FILE--
44
<?php
5-
define('foo::bar', 1);
6-
define('::', 1);
7-
?>
8-
--EXPECTF--
9-
Warning: Class constants cannot be defined or redefined in %sbug44827.php on line %d
105

11-
Warning: Class constants cannot be defined or redefined in %sbug44827.php on line %d
6+
try {
7+
define('foo::bar', 1);
8+
} catch (ValueError $exception) {
9+
echo $exception->getMessage() . "\n";
10+
}
11+
12+
try {
13+
define('::', 1);
14+
} catch (ValueError $exception) {
15+
echo $exception->getMessage() . "\n";
16+
}
17+
18+
?>
19+
--EXPECT--
20+
define(): Argument #1 ($constant_name) cannot be a class constant
21+
define(): Argument #1 ($constant_name) cannot be a class constant

Zend/tests/bug72162.phpt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ Bug #72162 (use-after-free - error_reporting)
44
<?php
55
error_reporting(E_ALL);
66
$var11 = new StdClass();
7-
$var16 = error_reporting($var11);
7+
8+
try {
9+
$var16 = error_reporting($var11);
10+
} catch (TypeError $exception) {
11+
echo $exception->getMessage() . "\n";
12+
}
813
?>
9-
--EXPECTF--
10-
Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in %s:%d
11-
Stack trace:
12-
#0 %s(%d): error_reporting(Object(stdClass))
13-
#1 {main}
14-
thrown in %s on line %d
14+
--EXPECT--
15+
error_reporting(): Argument #1 ($error_level) must be of type ?int, stdClass given

Zend/tests/closure_040.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ $a = new A(20);
2424
$ca = $a->getIncrementor();
2525
$cas = $a->getStaticIncrementor();
2626

27-
$ca->bindTo($a, array());
27+
try {
28+
$ca->bindTo($a, array());
29+
} catch (TypeError $exception) {
30+
echo $exception->getMessage() . "\n";
31+
}
32+
2833
$cas->bindTo($a, 'A');
2934

3035
?>

Zend/tests/constant_arrays.phpt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,21 @@ $y[0] = 3;
2424
var_dump($x, $y, QUX);
2525

2626
// ensure objects not allowed in arrays
27-
var_dump(define('ELEPHPANT', [new StdClass]));
27+
try {
28+
define('ELEPHPANT', [new StdClass]);
29+
} catch (TypeError $exception) {
30+
echo $exception->getMessage() . "\n";
31+
}
2832

2933
// ensure recursion doesn't crash
3034
$recursive = [];
3135
$recursive[0] = &$recursive;
32-
var_dump(define('RECURSION', $recursive));
36+
37+
try {
38+
define('RECURSION', $recursive);
39+
} catch (ValueError $exception) {
40+
echo $exception->getMessage() . "\n";
41+
}
3342
--EXPECTF--
3443
array(4) {
3544
[0]=>
@@ -92,9 +101,5 @@ array(1) {
92101
[0]=>
93102
int(7)
94103
}
95-
96-
Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d
97-
bool(false)
98-
99-
Warning: Constants cannot be recursive arrays in %s on line %d
100-
bool(false)
104+
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
105+
define(): Argument #2 ($value) cannot be a recursive array

0 commit comments

Comments
 (0)