krumo icon indicating copy to clipboard operation
krumo copied to clipboard

Is it possible to 'queue' so they can be displayed in bulk at once

Open nerdferby opened this issue 6 years ago • 2 comments

I found this library is very useful with debugging, but I came across an issue where using k() would send a header to the user, resulting in any cookies set later in the code to not be set at all (as they are also sent in the header).

So is it possible to queue a message to appear with a function is called, so you could queue a list of messages to be called at once later on so cookies are still able to be set? This could be done by using an array and a foreach loop but I thought it maybe more use to have this as a native method. Any help would be appreciated.

nerdferby avatar Jan 30 '20 15:01 nerdferby

Interesting idea... You could use

$html = k($data, KRUMO_RETURN):

And then print $html at the end of your script. It's not exactly what you want, but it's a hack that'll get roughly the same output.

scottchiefbaker avatar Jan 30 '20 16:01 scottchiefbaker

With a krumo::fetch() method as suggested in #51/#50 , it is easy to add support for that using register_shutdown_function(), like this:

	static function queue($data)
	{
		$output = call_user_func_array(
			array(get_called_class(), 'fetch'),
			func_get_args()
			);

		register_shutdown_function('printf', '%s', $output);
		return $output;
	}

It will preserve where the function was called from since the output is rendered on the fly, and only then queued to be printed at the end.

kktsvetkov avatar Aug 03 '20 09:08 kktsvetkov