|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54290 Class which extends from \SplFileObject is not serializable
Submitted: 2011-03-17 11:04 UTC Modified: 2020-04-20 15:16 UTC
Avg. Score:4.5 ± 0.7
Reproduced:7 of 7 (100.0%)
Same Version:6 (85.7%)
Same OS:2 (28.6%)
From: frederic dot hardy at mageekbox dot net Assigned: cmb (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
 [2011-03-17 11:04 UTC] frederic dot hardy at mageekbox dot net
It's impossible to implements \Serializable interface on a class which extends from \SplFileObject.

Test script:

namespace php\bugs\splFileObject;

class SerializableFileObject extends \SplFileObject implements \Serializable
  public function serialize()

  public function unserialize($serialized)


Expected result:

Actual result:
PHP Fatal error:  Class php\bugs\splFileObject\Serializable could not implement interface Serializable in Unknown on line 0


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-07 09:47 UTC] hanskrentel at yahoo dot de
According to the code it is intended that you can not serialize it.

Which can make sense as the file itself already is a serialized form 
of the object it represents. However different to DOMDocument where
serialization wouldn't make much sense (XML is a serialization 
already), in the SplFileObject case, Serialization is *explicitly* 
forbidden. The internal state of the object can not be preserved by
serialization, therefore it is just not possible.

This ticket can be closed as a duplicate of #46646 in my eyes or it 
needs to be turned into a feature-request, so that implementing 
Serializable might become possible - like it is with DOMDocument.
 [2020-04-20 15:16 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-04-20 15:16 UTC]
Indeed, serialization of SplFileObjects is deliberately
unsupported, and due to inherent issues with the Serializable
interface, at least this serialization mechanism will not be
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 15:01:24 2021 UTC