I have this helper function I use to log (into the serverside output) some events in my laravel app and is just working fine, but for a reason I can’t understand it fails with this specific case:
public static function consolelog(...$args): void{
foreach ($args as $arg) {
if (is_object($arg) || is_array($arg) || is_resource($arg)) {
$output = print_r($arg, true);
} else {
$output = (string) $arg;
}
fwrite(STDOUT, $output . "n");
}
}
In a middleware I verify a case where I want to abort a request but instead the app is just crashing when I try to print the string " URI:"
and it makes no sense to me why is it happening just for this case:
Funcoes::consolelog("Requisição inválida, headers:n");
Funcoes::consolelog(getallheaders());
Funcoes::consolelog(" Remote addr:");
Funcoes::consolelog($_SERVER['REMOTE_ADDR']);
Funcoes::consolelog(" URI:"); // it fails here without even printing the string
Funcoes::consolelog($_SERVER['REQUEST_URI']);
abort(400);
Error message:
In ServeCommand.php line 381:
Undefined array key 1
Php -v output (in case it’s useful):
$ php -v
PHP 8.3.11 (cli) (built: Aug 28 2024 22:31:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans