php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39635 Better control for serialization (keyword for permit property serialization)
Submitted: 2006-11-26 11:40 UTC Modified: 2017-10-24 06:12 UTC
Votes:13
Avg. Score:4.8 ± 0.6
Reproduced:12 of 12 (100.0%)
Same Version:7 (58.3%)
Same OS:8 (66.7%)
From: t dot prochazka at centrum dot cz Assigned:
Status: Open Package: *General Issues
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: t dot prochazka at centrum dot cz
New email:
PHP Version: OS:

 

 [2006-11-26 11:40 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-25 15:54 UTC] 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 ...
 [2009-11-09 15:53 UTC] tjerkw at gmail dot com
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.
 [2009-11-09 16:23 UTC] scottmac@php.net
Patch already exists, just need to discuss when is the correct time to add it.

http://whisky.macvicar.net/patches/php-transient.diff.txt
 [2010-12-20 09:26 UTC] jani@php.net
-Package: Feature/Change Request +Package: *General Issues -Operating System: all +Operating System: * -PHP Version: 5CVS-2006-11-26 (CVS) +PHP Version: *
 [2015-06-23 21:06 UTC] chealer at gmail dot com
I think we should rather ease serialization customization. If we could simply adjust the object before serialization, use the default serialization, then adjust tje object after a default unserialization, we could solve this case by simply unsetting problematic properties before serialization.
 [2017-10-24 06:12 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: scottmac +Assigned To:
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC