RE: OOP, Out of Scope Issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, 

 Please visit 

http://www.phpcertification.com/manual.php/functions.arguments.html#func
tions.arguments.by-reference

Hope it will be helpful.


zareef Ahmed 

-----Original Message-----
From: Jonathan Chum [mailto:jchum@xxxxxxxxxxxxx] 
Sent: Monday, November 08, 2004 9:52 AM
To: php-general@xxxxxxxxxxxxx
Subject:  OOP, Out of Scope Issue


I have a class called FrontEnd which extends a TemplateManager class.

The purpose of the TemplateManager class is to initate Smarty.

So my FrontEnd constructor looks like this:

function FrontEnd()
{
    $db = new DatabaseConnection();

    $this->db = $db->initDatabase();
    $this->sm = $this->initTemplate();
}

I have another function:

function DisplayMain($parentID)
{
    if (!isset($parentID)) $parentID = '1';

    $product = new Products($this->db, $this->sm);

    $category = new Categories($this->db, $this->sm);

    $category->FetchCategories($parentID);
    $product->FetchProducts($parentID);

    $this->DisplayPage('display-products');
}

I'm passing in an instance of the smarty object instantiated by the
FrontEnd 
constructor into Products and Categories. The FetchCategories and 
FetchProducts methods will take the smarty instance and assign the
variables 
into the template, assuming it's the same instance of Smarty. The
problem 
I'm having is that it sees in each class a new instance of Smarty or a
copy 
of the object which when I call DisplayPage, a method within the
FrontEnd 
class, it doesn't see all of the variables I assigned earlier by 
FetchProducts and FetchCategories even though I've not declared a new 
instance of Smarty.
How can I fix it so that it uses the same Smarty object and not a copy? 

------------------------------------------------------------------------
--
Zareef Ahmed :: A PHP develoepr in Delhi ( India )
Homepage :: http://www.zasaifi.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux