Jump to content

no output after object instantiated


andibakker

Recommended Posts

I am trying to learn smarty and OO Php by going through a sample application.  I have downloaded everything and setup libraries.  After I have instantiated my object, nothing displays.

 

I have set error_reporting(E_ALL);

 

In an effort to debug - I've put in the following echo statements in.

 

echo "before instantiating"; 

// create guestbook object 
$guestbook =& new Guestbook; 

$guestbook->sql->query("select * from guestbook", SQL_ALL); 
print_r($guestbook->sql->record);    
echo "after instantiating "; 

 

All that displays when I run this is :

 

Now when I run it, it only displays the following :

 

before instantiating

 

Please help

I am also new to OO php, so this could be something very basic that I'm overlooking.  I am not too sure why they use =& in the code to instantiate the object.  Below is the constructor for the guestbook class.

 

class Guestbook {
    public $testname = "testgbname";

// database object
    var $sql = null;
// smarty template object
    var $tpl = null;
// error messages
    var $error = null;
    
    /**
     * class constructor
     */
    function Guestbook() {

	// instantiate the sql object
        $this->sql =& new GuestBook_SQL;
	// instantiate the template object
        $this->tpl =& new Guestbook_Smarty;

\

 

and here is the Guestbook_SQL

 

class GuestBook_SQL extends SQL {
    function GuestBook_SQL() {
	    
        // dbtype://user:pass@host/dbname
        $dsn = "mysql://root:pass@localhost/guestbook";
       $this->connect($dsn) || die('could not connect to database');           		 
    }       
}

 

Please help, I have no idea where to go from here.  I also tried to access the $guestbook->testname  property, but that doesn't display anything either.

 

Thanks

Andi

Link to comment
https://forums.phpfreaks.com/topic/179058-no-output-after-object-instantiated/
Share on other sites

Use both of the following lines of code so that errors are both reported and displayed -

ini_set("display_errors", "1");
error_reporting(E_ALL);

 

On a development system, you should actually have these two settings in your master php.ini so that you don't need to put them into your files or remember to remove them when you put your finished code on a live server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.