#39635 [Com]: Better control for serialization (keyword for permit property serialization)

From: Date: Mon, 09 Nov 2009 15:53:55 +0000
Subject: #39635 [Com]: Better control for serialization (keyword for permit property serialization)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-144366@lists.php.net to get a copy of this message
ID: 39635 Comment by: tjerkw at gmail dot com Reported By: t dot prochazka at centrum dot cz Status: Open Bug Type: Feature/Change Request Operating System: all PHP Version: 5CVS-2006-11-26 (CVS) New Comment: Using a transient keyword is better because if we have the following case: class A { $a; $b; } class B extends A { $c function __sleep() { return array("c"); } } now if you serialize b you will not serialize the $a and $b members from class A. So the sleep functions actually changes the encapsulated behaviour of A. Or we should call the superclass A::__sleep() method and join that with the new arrow. However this is much cleaner code. And wether a member is transient or not should be declered nearby the member to keep else other developers may not now wether the member will be serialized or not. Previous Comments: ------------------------------------------------------------------------ [2007-01-25 15:54:50] spam at thishell dot com While it is possible to exclude members from serialization using __sleep(), it has downsides: - Using get_object_vars($this) to return the members is extremely slow - Manually maintaining an array with the members is error prone and can be quite some work A transient keyword to exclude members from serialization would make it easier ... ------------------------------------------------------------------------ [2006-11-26 11:40:40] t dot prochazka at centrum dot cz Description: ------------ PHP has no advanced support for serialization. I think, that is problem, that PHP serialize all properties. What about add single keyword (as transient) for property which can't be serializable? Example: class Foo { public $a; public transient $b; } Description of Java transient keyword: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78119 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39635&edit=1

« previous php.bugs (#144366) next »