Re: __sleep() strange behavior with file writting and SESSION using

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



chetan rane wrote:
> Sorry Buddie But Session dose not serialize the Object Please Have a look at
> the Code Again I have tried it with PHP 5.2
> IT dose not call __sleep function. only when you have serialize it calls it.

this is completely untrue. during the shutdown phase objects
in the $_SESSION superglobal are serialized and __sleep() is called if defined.

> 
> 
> On Nov 21, 2007 3:23 AM, Julien Pauli <doctorrock83@xxxxxxxxx> wrote:
> 
>> Sorry but it goes throught __sleep() as session serializes objects before
>> storing them
>> Proof is that "done!" is echoed.
>> Step by step debugging also prove that , the only thing is that
>> file_put_contents, doesn't execute, but returns a value...
>>
>>
>>
>> 2007/11/20, chetan rane <chetan.d.rane@xxxxxxxxx>:
>>
>>> This aint a bug
>>>
>>> because __sleep is called only when you serialize an object and not when
>>> you assign it to a session Variable;
>>>
>>> On Nov 21, 2007 12:21 AM, Julien Pauli < doctorrock83@xxxxxxxxx> wrote:
>>>
>>>> Consider that very simple code, that runs on PHP 5.2.5 onto a Windows
>>>> machine :
>>>> <?php
>>>> class a
>>>> {
>>>>    public $b;
>>>>
>>>>    public function __sleep()
>>>>    {
>>>>        file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
>>>>        echo "done!";
>>>>        return array();
>>>>    }
>>>> }
>>>>
>>>> $a = new a;
>>>> serialize($a);
>>>> ?>
>>>>
>>>> No problem here, log.txt is writtable, when it passes on the
>>>> serialize()
>>>> instruction, it goes to __sleep and works well.
>>>> "OK\r\n" is appended to the log file , and "done!" is displayed.
>>>>
>>>>
>>>>
>>>> Now consider this :
>>>>
>>>> <?php
>>>> session_start();
>>>> class a
>>>> {
>>>>    public $b;
>>>>
>>>>    public function __sleep()
>>>>    {
>>>>        file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
>>>>        echo "done!";
>>>>        return array();
>>>>    }
>>>> }
>>>>
>>>> $a = new a;
>>>> $_SESSION['obj'] = $a;
>>>> ?>
>>>>
>>>> In this case, when the object is going in the session, it naturally
>>>> passes
>>>> throught __sleep().
>>>> The problem is that file_put_contents() doesn't work -> the file is
>>>> not
>>>> appended "OK\r\n" as it should be.
>>>> "done!" is displayed , and if you look at the return value of
>>>> file_put_contents ( number of bytes that have been written ) : it's
>>>> all
>>>> right ! It simply doesn not write to the file.
>>>>
>>>> Anyone has an idea ?
>>>> Is this a bug ?
>>>> Thx :)
>>>>
>>>
>>>
>>> --
>>> Have A plesant Day
>>> Chetan. D. Rane
>>> Location: India
>>> Contact: +91-9844922489
>>> otherID: chetscool@xxxxxxxxx
>>>             chetrane@xxxxxxxxxxxxxx
>>>
>>
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux