No luck with FirePHP

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);
	}

}

?>


I accidentally 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?

I just read the FirePHP doc and it works with the HTTP headers, so it’s possible that the code executed after just “overrides” the headers or does a redirect and then you lose your debug information…

Is there a redirect after your line that “broke it” or something playing with the headers? Or maybe, somewhere after, the fire php log are cleared? (I don’t know if it’s possible, I never used it).

Anyway, you could find the faulty line by adding “die();” one block of lines at a time… Annoying task, but you’ll eventually find that bugger :wink: