pctechtv Posted March 24, 2014 Share Posted March 24, 2014 Hi, I am trying to use the FirePHP addon for Firefox to debug my PHP pages. I currently following training and feel the need to be able to have some introspection into what is going on. My knowledge of PHP is basic and I have just started really learning Object Oriented PHP. I don't find it easy to follow the trail of execution in a set of PHP files. So I wanted to use FirePHP to help. I am wondering what I am doing wrong and is anybody can help. I cannot seem to understand how to insert the code into the current pages to trace function execution. My code FirePHP code is around line 35 in the function find_by_sql. Could the fact that I am trying to use this on a static function be the problem. Thanks <?php ob_start(); // this is from the Lynda.com title PHP Beyond the Basics // If it's going to need the database, then it's // probably smart to require it before we start require_once('database.php'); require_once('../../FirePHPCore/fb.php'); class User { public $id; public $username; public $password; public $first_name; public $last_name; public static function find_all() { global $database; //$result_set = $database->query("SELECT * FROM users"); //return $result_set; return self::find_by_sql("SELECT * FROM users"); } public static function find_by_id($id=0) { global $database; $result_array = self::find_by_sql("SELECT * FROM users WHERE id={$id} LIMIT 1"); return !empty($result_array)? array_shift($result_array) : false; } public static function find_by_sql($sql="") { global $database; $firephp = FirePHP::getInstance(TRUE); $result_set = $database->query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)) { $object_array[] = self::instantiate($row); } $firephp->fb('Hello World!', FirePHP::TRACE); return $object_array; } public static function authenticate($username="", $password="") { global $database; $username = $database->escape_value($username); $password = $database->escape_value($password); $sql = "SELECT * FROM users "; $sql .= "WHERE username = '{$username}' "; $sql .= "AND password = '{$password}' "; $sql .= "LIMIT 1"; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } public function full_name() { if(isset($this->first_name) && isset($this->last_name)) { return $this->first_name . " " . $this->last_name; } else { return ""; } } private static function instantiate($record) { // Could check that $record exists and is an array // Simple, long-form approach: $object = new self; //$object->id = $record['id']; //$object->username = $record['username']; //$object->password = $record['password']; //$object->first_name = $record['first_name']; //$object->last_name = $record['last_name']; //return $object; // More dynamic, short-form approach foreach($record as $attribute=>$value){ if($object->has_attribute($attribute)) { $object->$attribute = $value; } } return $object; } private function has_attribute($attribute) { // get_object_vars returns an associative array with all attributes // (incl. private ones!) as the keys and their current values as the value $object_vars = get_object_vars($this); // We don't care about the value, we just want to know if the key exits // Will return ture or false return array_key_exists($attribute, $object_vars); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/ Share on other sites More sharing options...
gizmola Posted March 24, 2014 Share Posted March 24, 2014 I don't see an obvious problem. Did you follow the steps in the FAQ to debug: http://www.firephp.org/Wiki/Reference/FAQ Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473743 Share on other sites More sharing options...
pctechtv Posted March 24, 2014 Author Share Posted March 24, 2014 Thanks that page taught me how to check if the headers are getting sent. Mine look to be OK, I am just not getting my trace in the console. Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473746 Share on other sites More sharing options...
pctechtv Posted March 24, 2014 Author Share Posted March 24, 2014 I accidently broke the code trying things and it worked, that is until that point. Any idea what this means. I am not asking why the code broke I understand that, I am curious why it works when the function does not finish. Could this lead me to what I am ultimately doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473749 Share on other sites More sharing options...
gizmola Posted March 24, 2014 Share Posted March 24, 2014 You have a typo in there for your method call -- you're missing the greater than. $firephp-trace() needs to be $firephp->trace() Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473750 Share on other sites More sharing options...
pctechtv Posted March 24, 2014 Author Share Posted March 24, 2014 You have a typo in there for your method call -- you're missing the greater than. $firephp-trace() needs to be $firephp->trace() Thanks, I totally understand that, it is the whole point of what I said. I know why the code broke but why does FirePHP work now is what I am trying to figure out? If I fix it will not give me anything in the console. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473752 Share on other sites More sharing options...
gizmola Posted March 25, 2014 Share Posted March 25, 2014 If the headers are there, you should be seeing the information in firebug. It seems like a client-side issue. Are you saying that when you run your code you do not see anything in the firebug tab? Have you installed https://addons.mozilla.org/en-US/firefox/addon/firephp/ ? Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473859 Share on other sites More sharing options...
trq Posted March 26, 2014 Share Posted March 26, 2014 I wouldn't bother with firePHP, get yourself a proper debugger like xdebug or phpdbg. Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473904 Share on other sites More sharing options...
pctechtv Posted March 26, 2014 Author Share Posted March 26, 2014 I was having a hard time getting xdebug to work with local development. I have a setup with PHP MySQL and Apache installed separately, Can xdebug work with this? Do you know of any sites that Instruct for the configuration? I could only find info on getting it working with XAMMP Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473921 Share on other sites More sharing options...
trq Posted March 26, 2014 Share Posted March 26, 2014 I cover the basics here. What distro are you using? Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473932 Share on other sites More sharing options...
pctechtv Posted March 26, 2014 Author Share Posted March 26, 2014 I am using Windows with PHP MySQL and Apache installed on by one. I note the difference between use XAMMP or WAMP Server, because I see info how to use xdebug on those but don't find any info how to install if you have each one installed separately. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1473974 Share on other sites More sharing options...
trq Posted March 26, 2014 Share Posted March 26, 2014 It doesn't really make any difference. The process is the same, files and things might just be in different locations. Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1474036 Share on other sites More sharing options...
pctechtv Posted March 27, 2014 Author Share Posted March 27, 2014 (edited) It doesn't really make any difference. The process is the same, files and things might just be in different locations. I got it! What you said made me look at it again. Now I have xdebug working and can follow tutorials like yours. I am going to keep trying with FirePHP because it is nice to have another option. Thank you so much! Edited March 27, 2014 by pctechtv Quote Link to comment https://forums.phpfreaks.com/topic/287238-no-luck-with-firephp/#findComment-1474050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.