Re: Why does `setcookie` send header before throwing `Error` exception?
[email protected] (Jair López)
| Newsgroups | php.general |
|---|---|
| Message-ID | <PH0PR15MB436661DB3A6B2BA4BA9B3430E8789@PH0PR15MB4366.namprd15.prod.outlook.com> |
Sorry for the typos in my previous message. I stand corrected, it is
> setcookie('name', 'value', 1, new Foo());
instead of
> setcookie('name', 'value', 1, => new Foo());
and here is the fixed test file:
--TEST--
setcookie() sends header before throwing `Error` exception
--FILE--
<?php
ob_start();
class Foo{
}
try {
setcookie('name', 'value', array(
'expires' => 1,
'path' => new Foo()
));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
var_dump(headers_list());
echo "Done\n";
?>
--EXPECTHEADERS--
--EXPECTF--
Object of class Foo could not be converted to string
array(1) {
[0]=>
string(23) "X-Powered-By: PHP/8.0.3"
}
Done