Skip to content

Commit 720923e

Browse files
Tests
1 parent 340c7fd commit 720923e

File tree

4 files changed

+278
-0
lines changed

4 files changed

+278
-0
lines changed

sapi/cli/tests/gh8827-003.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ file_put_contents('php://fd/2', "Goes to stderrFile\n");
3434

3535
ob_start(function ($buffer) use ($stdoutStream) {
3636
fwrite($stdoutStream, $buffer);
37+
return '';
3738
}, 1);
3839

3940
print "stdoutFile:\n";
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
--TEST--
2+
ob_start(): Check behaviour with deprecation converted to exception
3+
--FILE--
4+
<?php
5+
6+
$log = [];
7+
8+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
9+
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
10+
});
11+
12+
function return_null($string) {
13+
global $log;
14+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
15+
return null;
16+
}
17+
18+
function return_false($string) {
19+
global $log;
20+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
21+
return false;
22+
}
23+
24+
function return_true($string) {
25+
global $log;
26+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
27+
return true;
28+
}
29+
30+
function return_zero($string) {
31+
global $log;
32+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
33+
return 0;
34+
}
35+
36+
$cases = ['return_null', 'return_false', 'return_true', 'return_zero'];
37+
foreach ($cases as $case) {
38+
$log = [];
39+
echo "\n\nTesting: $case\n";
40+
ob_start($case);
41+
echo "Inside of $case";
42+
try {
43+
ob_end_flush();
44+
} catch (\ErrorException $e) {
45+
echo $e . "\n";
46+
}
47+
echo "\nEnd of $case, log was:\n";
48+
echo implode("\n", $log);
49+
}
50+
51+
?>
52+
--EXPECTF--
53+
Testing: return_null
54+
ErrorException: ob_end_flush(): Returning a non-string result from user output handler return_null is deprecated in %s:%d
55+
Stack trace:
56+
#0 [internal function]: {closure:%s:%d}(8192, 'ob_end_flush():...', %s, %d)
57+
#1 %s(%d): ob_end_flush()
58+
#2 {main}
59+
60+
End of return_null, log was:
61+
return_null: <<<Inside of return_null>>>
62+
63+
Testing: return_false
64+
Inside of return_falseErrorException: ob_end_flush(): Returning a non-string result from user output handler return_false is deprecated in %s:%d
65+
Stack trace:
66+
#0 [internal function]: {closure:%s:%d}(8192, 'ob_end_flush():...', %s, %d)
67+
#1 %s(%d): ob_end_flush()
68+
#2 {main}
69+
70+
End of return_false, log was:
71+
return_false: <<<Inside of return_false>>>
72+
73+
Testing: return_true
74+
ErrorException: ob_end_flush(): Returning a non-string result from user output handler return_true is deprecated in %s:%d
75+
Stack trace:
76+
#0 [internal function]: {closure:%s:%d}(8192, 'ob_end_flush():...', %s, %d)
77+
#1 %s(%d): ob_end_flush()
78+
#2 {main}
79+
80+
End of return_true, log was:
81+
return_true: <<<Inside of return_true>>>
82+
83+
Testing: return_zero
84+
0ErrorException: ob_end_flush(): Returning a non-string result from user output handler return_zero is deprecated in %s:%d
85+
Stack trace:
86+
#0 [internal function]: {closure:%s:%d}(8192, 'ob_end_flush():...', %s, %d)
87+
#1 %s(%d): ob_end_flush()
88+
#2 {main}
89+
90+
End of return_zero, log was:
91+
return_zero: <<<Inside of return_zero>>>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
--TEST--
2+
ob_start(): Check behaviour with deprecation converted to exception
3+
--FILE--
4+
<?php
5+
6+
$log = [];
7+
8+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
9+
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
10+
});
11+
12+
function return_null($string) {
13+
global $log;
14+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
15+
return null;
16+
}
17+
18+
function return_false($string) {
19+
global $log;
20+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
21+
return false;
22+
}
23+
24+
function return_true($string) {
25+
global $log;
26+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
27+
return true;
28+
}
29+
30+
function return_zero($string) {
31+
global $log;
32+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
33+
return 0;
34+
}
35+
36+
ob_start('return_null');
37+
ob_start('return_false');
38+
ob_start('return_true');
39+
ob_start('return_zero');
40+
41+
echo "In all of them\n\n";
42+
try {
43+
ob_end_flush();
44+
} catch (\ErrorException $e) {
45+
echo $e->getMessage() . "\n";
46+
}
47+
echo "Ended return_zero handler\n\n";
48+
49+
try {
50+
ob_end_flush();
51+
} catch (\ErrorException $e) {
52+
echo $e->getMessage() . "\n";
53+
}
54+
echo "Ended return_true handler\n\n";
55+
56+
try {
57+
ob_end_flush();
58+
} catch (\ErrorException $e) {
59+
echo $e->getMessage() . "\n";
60+
}
61+
echo "Ended return_false handler\n\n";
62+
63+
try {
64+
ob_end_flush();
65+
} catch (\ErrorException $e) {
66+
echo $e->getMessage() . "\n";
67+
}
68+
echo "Ended return_null handler\n\n";
69+
70+
echo "All handlers are over\n\n";
71+
echo implode("\n", $log);
72+
73+
?>
74+
--EXPECT--
75+
ob_end_flush(): Returning a non-string result from user output handler return_null is deprecated
76+
Ended return_null handler
77+
78+
All handlers are over
79+
80+
return_zero: <<<In all of them
81+
82+
>>>
83+
return_true: <<<0ob_end_flush(): Returning a non-string result from user output handler return_zero is deprecated
84+
Ended return_zero handler
85+
86+
>>>
87+
return_false: <<<ob_end_flush(): Returning a non-string result from user output handler return_true is deprecated
88+
Ended return_true handler
89+
90+
>>>
91+
return_null: <<<ob_end_flush(): Returning a non-string result from user output handler return_true is deprecated
92+
Ended return_true handler
93+
94+
ob_end_flush(): Returning a non-string result from user output handler return_false is deprecated
95+
Ended return_false handler
96+
97+
>>>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
--TEST--
2+
ob_start(): Check behaviour with multiple nested handlers with had return values
3+
--FILE--
4+
<?php
5+
6+
$log = [];
7+
8+
function return_given_string($string) {
9+
global $log;
10+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
11+
return $string;
12+
}
13+
14+
function return_empty_string($string) {
15+
global $log;
16+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
17+
return "";
18+
}
19+
20+
function return_false($string) {
21+
global $log;
22+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
23+
return false;
24+
}
25+
26+
function return_true($string) {
27+
global $log;
28+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
29+
return true;
30+
}
31+
32+
function return_null($string) {
33+
global $log;
34+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
35+
return null;
36+
}
37+
38+
function return_string($string) {
39+
global $log;
40+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
41+
return "I stole your output.";
42+
}
43+
44+
function return_zero($string) {
45+
global $log;
46+
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
47+
return 0;
48+
}
49+
50+
ob_start('return_given_string');
51+
ob_start('return_empty_string');
52+
ob_start('return_false');
53+
ob_start('return_true');
54+
ob_start('return_null');
55+
ob_start('return_string');
56+
ob_start('return_zero');
57+
58+
echo "Testing...";
59+
60+
ob_end_flush();
61+
ob_end_flush();
62+
ob_end_flush();
63+
ob_end_flush();
64+
ob_end_flush();
65+
ob_end_flush();
66+
ob_end_flush();
67+
68+
echo "\n\nLog:\n";
69+
echo implode("\n", $log);
70+
?>
71+
--EXPECTF--
72+
Log:
73+
return_zero: <<<Testing...>>>
74+
return_string: <<<
75+
Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_zero is deprecated in %s on line %d
76+
0>>>
77+
return_null: <<<I stole your output.>>>
78+
return_true: <<<
79+
Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_null is deprecated in %s on line %d
80+
>>>
81+
return_false: <<<
82+
Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_true is deprecated in %s on line %d
83+
>>>
84+
return_empty_string: <<<
85+
Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_false is deprecated in %s on line %d
86+
87+
Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_true is deprecated in %s on line %d
88+
>>>
89+
return_given_string: <<<>>>

0 commit comments

Comments
 (0)