You are here: Re: __destruct() destroy an object that contains a reference to another object « PHP Programming Language « IT news, forums, messages
Re: __destruct() destroy an object that contains a reference to another object

Posted by Mortimer on 07/19/07 11:54

Scriveva gosha bine giovedì, 19/07/2007:
> On 19.07.2007 12:26 Mortimer wrote:
>>> I've noticed in your first example you didn't assign anything to
>>> MySecondClass->$obj, perhaps that is the problem ;)
>>
>> Sorry, i didn't write it, but i assign the object in the constructor, like
>> this:
>>
>> class Session {
>> private $db;
>> function __construct($db) {
>> $this->db = $db;
>> }
>> function __destruct() {
>> echo "Destroyed Session\n";
>> }}
>>
>> Uhm.. thank you
>>
>>
>
> I'm lost now. :-o
>
> What does this print for you?
>
>
> class Database {
> function __destruct() {
> echo "Destroyed Database\n";
> }}
> class Session {
> private $db;
> function __construct($db) {
> $this->db = $db;
> }
> function __destruct() {
> echo "Destroyed Session\n";
> }}
> $db = new Database;
> $sess = new Session($db);
> die();

This prints
Destroyed Database
Destroyed Session

:\

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация