|
Posted by Mortimer on 07/19/07 13:24
Il 19/07/2007, Mortimer ha detto :
> 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
>
> :\
So this doesn't work:
----------------------------------------------------
try
{
$db = new DBHandler($arrDataConn, DB);
}
catch(Exception $e)
{
exit("Service not available");
}
$sess = new DBSession($db);
----------------------------------------------------
While this seems to work fine:
----------------------------------------------------
$sess = new DBSession($db = new DBHandler($dataConn, DB))
----------------------------------------------------
So i can use $db object after the instance of $sess;
I'll report this to the php.net site as a bug
Navigation:
[Reply to this message]
|