UserFrosting icon indicating copy to clipboard operation
UserFrosting copied to clipboard

[FEATURE REQUEST] Make Debug::debug second parameter accept all kind of variables

Open ktecho opened this issue 4 years ago • 2 comments

Right now, at least on my setup, if you pass a variable that is not an array to the second parameter of a Debug::debug expression, the execution is halted with an error:

var1 = 'Hey there';
Debug::debug('Value of variable:', var1);
functionAA();
Argument 2 passed to Monolog\Logger::debug() must be of the type array, string given, called in /app/app/system/Facade.php on line 239

That will not print the debug and the functionAA is not executed either because the Debug failed.

Would it be difficult to accept all kind of variables and just dump them to the log? The current way I need to check every time if what I want to print is an array. I've ended putting [ ] around everything just to be sure.

Maybe we can do something like:

if (variable_passed is type array) {
     dump variable_passed;
} else {
    dump [variable_passed];
}

ktecho avatar Mar 20 '20 10:03 ktecho

Editing to reflect that you don't get error message in the log, but I'm getting it on the screen.

ktecho avatar Mar 20 '20 10:03 ktecho

Looks like a limitation on Monolog side. We would need to encapsulate the debug method so we convert string to array manually.

FYI, I usually do, with whatever kind of var I have :

Debug::debug(print_r($foo, true));

(or use XDebug 😁 )

lcharette avatar Mar 20 '20 13:03 lcharette

Debug facade is not available in UF5 anymore.

lcharette avatar Nov 25 '23 02:11 lcharette