CodeIgniter
CodeIgniter copied to clipboard
Error in codeigniter's Output.php file (system/core/Output.php)
Error: Message: str_replace(): Passing null to parameter #3 ($output) of type array|string is deprecated
You need to replace at line no. 457 in system/core/Output.php
$output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output);
with this
$output = $output ? str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output): "";
Hi!
Can you please provide an example of a code snippet to reproduce the issue? Are you altering any other property of CI_Output? What PHP version are you using?
@gxgpet It is not easy to reproduce the error, but what I know is, it returns an empty view to the browser and I realized it is a deprecation error.
When you look at the code below I just added an if block to check if $output is equal to null and then set it to an empty string
And that fixed it.
// Parse out the elapsed time and memory usage,
// then swap the pseudo-variables with the data
$elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');
if ($this->parse_exec_vars === true) {
if ($output === null) {
$output = ''; // this is how I fixed it;
}
$memory = round(memory_get_usage() / 1024 / 1024, 2) . 'MB';
$output = str_replace(['{elapsed_time}', '{memory_usage}'], [$elapsed, $memory], $output);
}