Link to home
Start Free TrialLog in
Avatar of elepil
elepil

asked on

PHP Debugging question

I am new to PHP, so this is a newbie question. Let's say I have this code:

$.ajax({
	url: "somepage.php",
        .
        .
  })

Open in new window


"somepage.php" is a page that accesses the database and returns results via an "echo" statement.

My question is, what PHP commands do PHP developers use to debug "somepage.php"? For example, let's say I just wanted to see the value in a variable, how do I output it the way you'd use console.log() in JavaScript? I can't use "echo" because PHP will treat it as output being sent to the calling page.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elepil
elepil

ASKER

To Marco Gasi. You said:

Otherwise, if you find problem, you can serializaze your variables and echo them as result of the script and use javascript to put them in the console.

How do I serialize my variables?
You can just create an array with the variables you want to debug and then echoing it using json_encode:

$arr = array("firstname" => $firstname, "lastname" => $lastname, and so on);
echo json_encode($arr);

Open in new window


Then in your javascript:

$.ajax({
	url: "somepage.php",
        . ,
        . ,
        dataType: 'json',
        success: function(result){
             $(result).each(function(key, value){
                  console.log(key + ' = ' + value);
             }
        }
        ...
  })

Open in new window

Avatar of elepil

ASKER

Marco, I tried to install FirePHP. The instructions in firephp.org talk about a FirePHPCore folder that I am supposed to put in my application root. Problem is, I can't find that folder! When I installed it in my Firefox, it never asked me for any install directory, it just added FirePHP, and I can see it as an add-on. I tried doing a disk search through Windows Explorer for "FirePHPCore" and found nothing.

Where the heck is that folder??
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi elepil.
Go here to download FirePhp: http://www.firephp.org/HQ/Install.htm
You can follow this tutorial: I followed it me too.
Avatar of elepil

ASKER

Marco. I've already installed both FireBug and FirePHP. It is apparent to me from code samples that I need FirePHPCore, something I could not find nor download (because one of the links in the page you referred me to led to Page Not Found).

It's not that I don't know how to use it, because it seems simple. I think all I need to do is put FirePHPCore folder somewhere in my application root, then "include" it in any page I want to debug, then use its FD::log/info/warn/error static methods. My problem is I can't find FirePHPCore.
Avatar of elepil

ASKER

To Scott Fel. Thanks for responding.

The only times I've had to use Network was when I needed to look into headers information or when I needed to see the incoming data in its raw format. If I were debugging an "off-by-one" situation within a small piece of code in the page, I don't see how Network would help.
The network also shows the response generated. There are tabs for header,preview, response,timing.   However, I find it easier to just surf to the somepage.php and fiddler with different querystrings to view the response.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's way I posted that link: just click on Download link and you'll get all needed files.
Avatar of elepil

ASKER

I found a good one called ChromePhp. But FirePhp is something to keep in mind. Thanks to all who responded.