Jump to content
MakeWebGames

Debug in PHP


HazardBoy

Recommended Posts

I saw some people having issues with php and don't know what is wrong.

And I believe that php tells you where it hurts just like JavaScript.

if something is not working and you can't see why. Make sure you have error reporting on. :)

 

<?php
  ini_set('display_errors', 'On');
  error_reporting(E_ALL);

 

I also use print_r() and var_dump(); to see if print is reach and data is there.

What else is there to debug php and track errors?

Link to comment
Share on other sites

If we are on about PHP, generally the framework at hand handles the errors, however using PHP and JS, I have the following method.

Javascript

   $("form").on("submit", function(e)
   {
       e.preventDefault();

       var submitButton = $(this).closest('form').find(':submit');

       var form = $(this);

       if(submitButton.hasClass('bconfirm'))
       {
           bootbox.confirm(submitButton.data('box'), function(result)
           {
               if(result === true)
                   lib.submit(form);
           })
       }
       else
       {
           lib.submit(form);
       }


   });

 

PHP

$std = new \StdClass();
$std->alert = $db->error();

 

And finally on the ajax request to submit my form

                   if(("alert" in data))
                   {
                       bootbox.alert(data.alert);
                       console.log('Data alert');
                   }

 

Basically PHP has a database error -> The main module catches it -> throws out a json response -> javascript displays it in a pretty format

Link to comment
Share on other sites

What else is there to debug php and track errors?

well you can install xdebug and setup breakpoints into your script inside IDE and then track you variables. also there exists FirePHP which allows you to display you values inside FireBug extension insdead on the page. also there are PHP/Apache logfiles which are often ignored

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...