elepil
asked on
PHP Debugging question
I am new to PHP, so this is a newbie question. Let's say I have this code:
"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.
$.ajax({
url: "somepage.php",
.
.
})
"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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can just create an array with the variables you want to debug and then echoing it using json_encode:
Then in your javascript:
$arr = array("firstname" => $firstname, "lastname" => $lastname, and so on);
echo json_encode($arr);
Then in your javascript:
$.ajax({
url: "somepage.php",
. ,
. ,
dataType: 'json',
success: function(result){
$(result).each(function(key, value){
console.log(key + ' = ' + value);
}
}
...
})
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??
Where the heck is that folder??
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi elepil.
Go here to download FirePhp: http://www.firephp.org/HQ/Install.htm
You can follow this tutorial: I followed it me too.
Go here to download FirePhp: http://www.firephp.org/HQ/Install.htm
You can follow this tutorial: I followed it me too.
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.
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.
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 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That's way I posted that link: just click on Download link and you'll get all needed files.
ASKER
I found a good one called ChromePhp. But FirePhp is something to keep in mind. Thanks to all who responded.
ASKER
How do I serialize my variables?