Page 1 of 1

Using echo to trace

Posted: 13 Nov 2020, 10:02
by PacoA
Hi.
It could be a silly question but I had no answer by searching.
Why 'echo' or 'print' doesn´t work?

I´m triyng to trace my code with simple displays but I can´t see them

Re: Using echo to trace

Posted: 13 Nov 2020, 18:41
by atrol
Depends on where you have placed your code.
Your code might not be executed at all, or you can't see the output as the page is sent ompletely new shortly after your code has been executed.

To find out if it's executed, just place some line like

Code: Select all

die ("Hello I am here"); 
in it.

Re: Using echo to trace

Posted: 15 Nov 2020, 12:23
by PacoA
Hi. Thanks.
My code is executing.
Actually I´m tracing by using 'bugnote_add' function.

Even thoug I´v tried your suggestion and it works, the process die ;). But replacing die by echo does anything.

Re: Using echo to trace

Posted: 15 Nov 2020, 13:51
by atrol
PacoA wrote: 15 Nov 2020, 12:23But replacing die by echo does anything.
Anything? I suppose you mean nothing.

If I understand right, you want to trace a low level function of Mantis (bugnote_add) by using echo statements.
This is a bad idea in general, as most of the time a new page will be generated after the echo, so you will not see the outpout.
You could add another "die" after your "echo" and I am pretty sure you will see your echo.

It would be better to learn how to debug PHP applications (e.g. by using Xdebug) in general, or use some PHP standard functionality for logging https://www.loggly.com/ultimate-guide/p ... ing-basics or use/check how function log_event is used in Mantis depending on options $g_log_level and $g_log_destination

Re: Using echo to trace

Posted: 15 Nov 2020, 19:41
by PacoA
Sorry about my english. As bad as my php programming.

Of course I meant "nothing".

I´m trying to trace a plugin. I´m using bugnote_add to trace, because I don´t see echoes. Write in a bugnote the text I cannot display.

My code is working. So I don´t need help with that. It´s only that seems strange cannot use echo to trace.

Another reason to hate php :mrgreen:

Anyway, I will check your contributions.

Thank you for your time.