|  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: 2020-02-13 17:28 UTC
Avg. Score:4.6 ± 0.7
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: Suspended Package: *General Issues
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-11-26 11:40 UTC] t dot prochazka at centrum dot cz
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?


class Foo {
 public $a;
 public transient $b;


Description of Java transient keyword:


Add a Patch

Pull Requests

Add a Pull Request


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 

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]
Patch already exists, just need to discuss when is the correct time to add it.
 [2010-12-20 09:26 UTC]
-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]
-Status: Assigned +Status: Open -Assigned To: scottmac +Assigned To:
 [2020-02-13 17:28 UTC]
-Status: Open +Status: Suspended
 [2020-02-13 17:28 UTC]
> PHP has no advanced support for serialization.

PHP has already different ways to customize serialization, namely
__sleep()[1] and Serializable[2], the latter being superseeded by
__serialize()[3] as of PHP 7.4.0.  Adding support for the
transient keyword (or similar) *might* make sense, but that should
be discussed on the internals mailing list[4].  Feel free to start
that discussion; for the time being, I'm suspending this ticket.

[1] <>
[2] <>
[3] <>
[4] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jul 30 18:01:30 2021 UTC