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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
No tabs
  • Loading branch information
DanielEScherzer committed Jun 26, 2025
commit 25c35b8bcee8b33ffdde28058d7af919cd1d234c
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