|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72884 SplObject isCloneable() returns true but errs on clone
Submitted: 2016-08-18 16:34 UTC Modified: 2019-09-09 17:14 UTC
From: php at abiusx dot com Assigned: jhdxr (profile)
Status: Closed Package: SPL related
PHP Version: 7.0.9 OS: OS X 10.11
Private report: No CVE-ID: None
 [2016-08-18 16:34 UTC] php at abiusx dot com
An SplFileObject is clonable according to reflection, but errs on attempting to clone.

Related bug report: 53967

Test script:
$x=new SplFileObject("tests.php");
$r=new ReflectionObject($x);

$y=clone $x; //fatal error

Expected result:
At worst, such things should issue a warning. This clone might happen as part of more general clone that involves many objects and arrays, and with a fatal error there is no way to recover from this, but it is not a big deal and should be recoverable.

Changing it to E_WARNING is a possible scenario, or throwing appropriate exceptions on PHP 7.

Also, note in the documentation that reflection stats are not accurate regarding core classes and functions.

Actual result:
make cloneable, return false, or E_WARNING


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-19 03:14 UTC]
hmm, the codes lead to segfault in 7.1
 [2018-08-15 17:49 UTC]
-Status: Open +Status: Verified
 [2018-08-15 17:49 UTC]
The problem is that SplFileObject reuses the object handlers of
SplFileInfo, which defines a clone_obj handler[1], which signals
to reflection that it is cloneable, but throws an error there[2].

[1] <>
[2] <>
 [2019-09-08 09:48 UTC]
The following pull request has been associated:

Patch Name: fix bug #72884  isCloneable() on SplFileObject should return false
On GitHub:
 [2019-09-09 15:30 UTC]
Automatic comment on behalf of
Log: Fix bug #72884 isCloneable() on SplFileObject should return false
 [2019-09-09 15:30 UTC]
-Status: Verified +Status: Closed
 [2019-09-09 17:14 UTC]
-Assigned To: +Assigned To: jhdxr
 [2019-09-09 17:14 UTC]
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from and re-test.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon May 29 10:03:44 2023 UTC