Ticket #803 (closed defect: fixed)

Opened 8 months ago

Last modified 2 months ago

__sleep() function in TActiveRecord

Reported by: short Owned by: xue
Priority: normal Milestone: 3.1.2
Component: Prado Framework v3 Version: 3.1
Severity: minor Keywords:
Cc:

Description

Hi,

there is an inconsistency in PHP's calling of the _ _sleep function on objects, which results in incorrectly omitting serialization of private variables from ancestor classes. Details can be found in this thread in the Prado Forum.

To summarize, there are two problems in TActiveRecord:

  • The variable _readOnly is private, and there is a _ _sleep() function present, which results in PHP not serializing the variable when a class derived from TActiveRecord is serialized. It also throws a notice in some cases.
  • The _ _wake() function should be called _ _wakeup().

Just removing the _ _sleep() function was remedy for the unwanted notice PHP threw.

Change History

Changed 8 months ago by donkee

The function __sleep() shouldn't de deleted but fixed. This method permit serialization of object for be saved between different request of the user.

The function should don't return a table which contain name of all members of class. He should only have the public one.

The function __wake() should effectivelly renamed as __wakeup() this one permit to finish initialization of object after serialization.

But i think that this function is bugged too. Because the private var _recordState stay at 0 which will maybe an inconsistant state for TActiveRecord.

Changed 8 months ago by short

I agree that it should better be fixed, however, since it returns all object variables anyway, there would be no change in simply deleting it. I think fixing it would be impossible with the current state of PHP, since there is the problem with calling __sleep() on an inherited class I described on the thread. This bug with serialization of private variables leads to _readOnly not being serialized.

Why should it return only public members?

Changed 8 months ago by donkee

You work with the Prado v3.1 which is revision 2290 in SVN repository. If take care about reading the last revision, you can see that the problem of serialization has allready been resolved.

But for the problem of unserialization is still here. And function __wake() must be renamed as __wakeup()

Changed 7 months ago by xue

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to 3.1.2

Thanks for the discussion. I will change _recordState to protected to solve this problem. It's not pretty, but I don't have any other solution without big change.

Changed 7 months ago by jake

  • status changed from closed to reopened
  • resolution fixed deleted

This problem is still an issue! I downloaded the latest head and hoped it was fixed but I still get that problem on php 5.2.5!

I even made a thread about it with all the errors I got...

http://www.pradosoft.com/forum/index.php/topic,9780.0.html

Changed 7 months ago by jake

I'm sorry this ticket can be closed again. I reopened that ticket because I was experiencing the same error and had the same symptoms of this ticket so I thought it was the same thing. Later when I resolved my issue I learned that it was something else. Sorry there is another ticket created for the issue I had.

Thanks, - Jake

Changed 7 months ago by tof06

  • status changed from reopened to closed
  • resolution set to fixed

Changed 6 months ago by schmunk

Although this bug is closed, I think these two links are pretty interesting. They explain how to treat private and protected variables with sleep() functions: http://www.php.net/manual/en/language.oop.serialization.php#81642 http://us.php.net/manual/en/language.oop5.magic.php#81492

Changed 3 months ago by sergeymorkovkin

  • status changed from closed to reopened
  • resolution fixed deleted

Changed 2 months ago by knut

  • status changed from reopened to closed
  • resolution set to fixed

I'm closing this one since the the original problem related to private $_recordState is solved. For private $_connection see #855.

Note: See TracTickets for help on using tickets.