RE: [PHP] OOP, Out of Scope Issue
| From: | Zareef Ahmed | Date: | Mon, 08 Nov 2004 04:45:46 +0000 |
| Subject: | RE: [PHP] OOP, Out of Scope Issue | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-201483@lists.php.net to get a copy of this message | ||
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@cc.gatech.edu]
Sent: Monday, November 08, 2004 9:52 AM
To: php-general@lists.php.net
Subject: [PHP] 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