Skip to content
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

Error in codeigniter's Output.php file (system/core/Output.php) #6177

Open
spicer1 opened this issue Nov 16, 2022 · 2 comments
Open

Error in codeigniter's Output.php file (system/core/Output.php) #6177

spicer1 opened this issue Nov 16, 2022 · 2 comments

Comments

@spicer1
Copy link

spicer1 commented Nov 16, 2022

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): "";

@gxgpet
Copy link
Contributor

gxgpet commented Dec 1, 2022

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?

@otengkwame
Copy link

@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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants