Re: OOP, Out of Scope Issue
| From: | Jonathan Chum | Date: | Mon, 08 Nov 2004 05:15:13 +0000 |
| Subject: | Re: OOP, Out of Scope Issue | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-201485@lists.php.net to get a copy of this message | ||
Awesome, great tip. It works just fine in PHP 5, but after gooogling more
information about references and values, it appears that PHP 5 supports
references automatically.
I was trying to get it to work under 4.3.8 which I had to use the &.
For anyone else, this page goes into more depth:
http://www.webreference.com/programming/phpanth2/5.html
Thanks!
"Zareef Ahmed" <za@lmpx.com> wrote in message
news:003401c4c54d$d21483d0$0100a8c0@vsserver...
>
> 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