Skip to content

Commit 5770b66

Browse files
committed
Cleanup argument handling of Zend functions and methods
Closes GH-5847
1 parent 42226fc commit 5770b66

31 files changed

+326
-272
lines changed

Zend/tests/001.phpt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@ class test {
4040
}
4141

4242
test::test1(1);
43-
var_dump(func_num_args());
43+
44+
try {
45+
func_num_args();
46+
} catch (Error $exception) {
47+
echo $exception->getMessage() . "\n";
48+
}
4449

4550
echo "Done\n";
4651
?>
4752
--EXPECTF--
4853
int(0)
4954
int(1)
50-
Exception: Too few arguments to function test2(), 0 passed in %s001.php on line 18 and exactly 1 expected
55+
Exception: Too few arguments to function test2(), 0 passed in %s on line %d and exactly 1 expected
5156
int(2)
5257
int(0)
53-
Exception: Too few arguments to function test3(), 1 passed in %s001.php on line 27 and exactly 2 expected
58+
Exception: Too few arguments to function test3(), 1 passed in %s on line %d and exactly 2 expected
5459
int(2)
5560
int(1)
56-
57-
Warning: func_num_args(): Called from the global scope - no function context in %s on line %d
58-
int(-1)
61+
func_num_args() must be called from a function context
5962
Done

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 ($position) must be greater than or equal to 0
100+
func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
101+
func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
102+
func_get_arg(): Argument #1 ($position) 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 ($position) 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 ($position) 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 ($position) must be less than the number of the arguments passed to the currently executed function
111+
func_get_arg(): Argument #1 ($position) must be greater than or equal to 0
112+
func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
113+
func_get_arg(): Argument #1 ($position) 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 ($position) 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 ($position) 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) cannot be an object, stdClass given
4346
int(1)
4447
int(2)
4548
int(3)

Zend/tests/010.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ bool(false)
7575
string(3) "foo"
7676
bool(false)
7777
bool(false)
78-
get_parent_class(): Argument #1 ($object) must be a valid class name or object, string given
79-
get_parent_class(): Argument #1 ($object) must be a valid class name or object, string given
80-
get_parent_class(): Argument #1 ($object) must be a valid class name or object, string given
78+
get_parent_class(): Argument #1 ($object_or_class) must be a valid class name or object, string given
79+
get_parent_class(): Argument #1 ($object_or_class) must be a valid class name or object, string given
80+
get_parent_class(): Argument #1 ($object_or_class) must be a valid class name or object, string given
8181
bool(false)
82-
get_parent_class(): Argument #1 ($object) must be a valid class name or object, array given
83-
get_parent_class(): Argument #1 ($object) must be a valid class name or object, int given
82+
get_parent_class(): Argument #1 ($object_or_class) must be a valid class name or object, array given
83+
get_parent_class(): Argument #1 ($object_or_class) must be a valid class name or object, int given
8484
Done

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 ($position) 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) cannot be an object, 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/class_alias_006.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ Testing creation of alias to an internal class
33
--FILE--
44
<?php
55

6-
class_alias('stdclass', 'foo');
6+
try {
7+
class_alias('stdclass', 'foo');
8+
} catch (ValueError $exception) {
9+
echo $exception->getMessage() . "\n";
10+
}
711

812
?>
9-
--EXPECTF--
10-
Warning: First argument of class_alias() must be a name of user defined class in %s on line %d
13+
--EXPECT--
14+
class_alias(): Argument #1 ($class) must be a user-defined class name, internal class name given

Zend/tests/closure_040.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $ca = $a->getIncrementor();
2525
$cas = $a->getStaticIncrementor();
2626

2727
$ca->bindTo($a, array());
28+
2829
$cas->bindTo($a, 'A');
2930

3031
?>

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) cannot be an object, stdClass given
105+
define(): Argument #2 ($value) cannot be a recursive array

Zend/tests/constants_002.phpt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ Defining constants with non-scalar values
33
--FILE--
44
<?php
55

6-
define('foo', new stdClass);
6+
try {
7+
define('foo', new stdClass);
8+
} catch (TypeError $exception) {
9+
echo $exception->getMessage() . "\n";
10+
}
11+
712
try {
813
var_dump(foo);
914
} catch (Error $e) {
@@ -14,7 +19,7 @@ define('foo', fopen(__FILE__, 'r'));
1419
var_dump(foo);
1520

1621
?>
17-
--EXPECTF--
18-
Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d
22+
--EXPECT--
23+
define(): Argument #2 ($value) cannot be an object, stdClass given
1924
Undefined constant "foo"
2025
resource(5) of type (stream)

0 commit comments

Comments
 (0)