[SOLVED] How debug PHP code?

F.schettino

Italian
I am learning PHP and JavaScript using Fabrik.

I use "alert" to debug JavaScript (I display values of variables step by step).
How can I get something similar debugging PHP?

At the moment, I need to debug PHP in Validation of an element (PHP validation).

I would appreciate a lot an help.
Thank you.
 
At the moment, I need to debug PHP in Validation of an element (PHP validation).
but I will have other needs.

Now I have to check (and eventually validate) if
year of birth >= current year-80 years And year of birth<= current year-20 years
 
In php - for variables you can use echo $var and they will print at the top of the browser window... for arrays (data sets) you can use var_dump($var)...

Code:
//print the value of a variable
echo $var;
 
//print array content
var_dump($var);
 
I usually find just var_dump() is best, as it'll always dump out the data, regardless of data type., no need to worry about what you are dumping.

Also, be aware that if you are dumping out data during form submissions, you often won't see the debug output, unless you abort the submission process. This is because after every succesful form submission there is a redirect. So the the browser never display anything that was output during the page buiding of the submission. So for instance, in a validation, you'll probably see it if the validation fails, but not if the submission succeeds.

The two ways round that, so you see the data for a succesful submission, are:

var_dump($foo);exit;

... to put an 'exit' after the dump, which aborts the page build / submission at that point, and just returns to the browser. So you'll get a white page with just the debug data.

The other way is to append &fabrikdebug=2 to the URL that loads the form. This is a recent addition, which tells us to skip all redirects after a form submission, and just load an empty J! page, with just debug info on it.

-- hugh
 
Thank you very much, cheesegrits!
I'll try and I'll give you feedback, useful for other people; I think that there is here a lot of people that don't know PHP and JS, as me.
I'm learning by reading Fabrik documentation and trying, trying, trying, ...

As you can see, it is I who must thank you, you do not have to thank me :).
 
WOOOW!

It is very useful, cheesegrits:
  • if there aren't errors, I get a white page with the data
  • if there is an error, I don't get it; so I know that there is something wrong.
Thank you.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top