|
Posted by Jerry Stuckle on 07/19/07 13:33
Rik wrote:
> On Thu, 19 Jul 2007 13:58:05 +0200, Mortimer <leandro980@gmail.com> wrote:
>
>> Scriveva Jerry Stuckle giovedì, 19/07/2007:
>>> Mortimer wrote:
>>>> Hi, i'm using PHP 5.1
>>>> I have two objects and the second one is using an instance of the
>>>> first.
>>>> As displayed in the example below, the Garbage Collector calls the
>>>> destruct method of the first class before the second even if the
>>>> second contains a reference to the other, so i can't complete all
>>>> the operations not having all "the code available"!
>>>> Thank you
>>>> Ex.:
>>>> class MyFirstClass
>>>> {
>>>> public function __construct()
>>>> {
>>>> ... operations...
>>>> }
>>>> public function __destruct()
>>>> {
>>>> echo "Destroyed MyFirstClass";
>>>> }
>>>> }
>>>> class MySecondClass
>>>> {
>>>> private $obj = NULL
>>>> public function __construct($obj)
>>>> {
>>>> ... operations...
>>>> }
>>>> public function __destruct()
>>>> {
>>>> echo "Destroyed MySecondClass";
>>>> }
>>>> }
>>>> $obj1 = new MyFirstClass();
>>>> $obj2 = new MySecondClass($obj1);
>>>> // Result
>>>> // Destroyed MyFirstClass
>>>> // Destroyed MySecondClass
>>>>
>>>
>>> Hmmm, personally I would consider this to be a bug. I'd suggest you
>>> report it and see what they say.
>>>
>>
>> Uhm.. ok.. do you mean in the php.net site or in a Newsgroup?
>
> I'd think http://bugs.php.net/.
> But then again, I cannot find anything in the documentation where it
> explicitly states that variables are detroyed/cleaned up in a particular
> order. Anyone?
>
> --Rik Wasmus
Hi, Rik,
No, I can't find it either. But destructors are still fairly new to
PHP, so it might not have been considered.
In C++, for instance, destruction is in the opposite order of creation
(in the same module - intermodule dependencies are not guaranteed). It
seems to work well.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|