8000 Deprecate returning non-string values from a user output handler by DanielEScherzer · Pull Request #18932 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content

Deprecate returning non-string values from a user output handler #18932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
No tabs
  • Loading branch information
DanielEScherzer committed Jul 3, 2025
commit 771024010243d1e909df8a01d70b4a29a23ba9ef
38 changes: 19 additions & 19 deletions tests/output/ob_start_callback_bad_return/exception_handler.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,42 @@ set_error_handler(function (int $errno, string $errstr, string $errfile, int $er
});

function return_null($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return null;
}

function return_false($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return false;
}

function return_true($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return true;
}

function return_zero($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return 0;
}

$cases = ['return_null', 'return_false', 'return_true', 'return_zero'];
foreach ($cases as $case) {
$log = [];
echo "\n\nTesting: $case\n";
ob_start($case);
echo "Inside of $case\n";
try {
ob_end_flush();
} catch (\ErrorException $e) {
echo $e . "\n";
}
echo "\nEnd of $case, log was:\n";
echo implode("\n", $log);
$log = [];
echo "\n\nTesting: $case\n";
ob_start($case);
echo "Inside of $case\n";
try {
ob_end_flush();
} catch (\ErrorException $e) {
echo $e . "\n";
}
echo "\nEnd of $case, log was:\n";
echo implode("\n", $log);
}

?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ set_error_handler(function (int $errno, string $errstr, string $errfile, int $er
});

function return_null($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return null;
}

function return_false($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return false;
}

function return_true($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return true;
}

function return_zero($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return 0;
}

Expand All @@ -40,30 +40,30 @@ ob_start('return_zero');

echo "In all of them\n\n";
try {
ob_end_flush();
ob_end_flush();
} catch (\ErrorException $e) {
echo $e->getMessage() . "\n";
echo $e->getMessage() . "\n";
}
echo "Ended return_zero handler\n\n";

try {
ob_end_flush();
ob_end_flush();
} catch (\ErrorException $e) {
echo $e->getMessage() . "\n";
echo $e->getMessage() . "\n";
}
echo "Ended return_true handler\n\n";

try {
ob_end_flush();
ob_end_flush();
} catch (\ErrorException $e) {
echo $e->getMessage() . "\n";
echo $e->getMessage() . "\n";
}
echo "Ended return_false handler\n\n";

try {
ob_end_flush();
ob_end_flush();
} catch (\ErrorException $e) {
echo $e->getMessage() . "\n";
echo $e->getMessage() . "\n";
}
echo "Ended return_null handler\n\n";

Expand Down
30 changes: 15 additions & 15 deletions tests/output/ob_start_callback_bad_return/multiple_handlers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ ob_start(): Check behaviour with multiple nested handlers with had return values
$log = [];

function return_given_string($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return $string;
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return $string;
}

function return_empty_string($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return "";
}

function return_false($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return false;
}

function return_true($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return true;
}

function return_null($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return null;
}

function return_string($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return "I stole your output.";
}

function return_zero($string) {
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
global $log;
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>";
return 0;
}

Expand Down
0