php.net |  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
Description:
------------
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);
var_dump($r->isCloneable());

$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

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-19 03:14 UTC] laruence@php.net
hmm, the codes lead to segfault in 7.1
 [2018-08-15 17:49 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2018-08-15 17:49 UTC] cmb@php.net
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] <https://github.com/php/php-src/blob/php-7.3.0beta1/ext/spl/spl_directory.c#L3097>
[2] <https://github.com/php/php-src/blob/php-7.3.0beta1/ext/spl/spl_directory.c#L374>
 [2019-09-08 09:48 UTC] jhdxr@php.net
The following pull request has been associated:

Patch Name: fix bug #72884  isCloneable() on SplFileObject should return false
On GitHub:  https://github.com/php/php-src/pull/4688
Patch:      https://github.com/php/php-src/pull/4688.patch
 [2019-09-09 15:30 UTC] nikic@php.net
Automatic comment on behalf of me@jhdxr.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1ac6b0251b6585490dfb549eb70b8c618cf90913
Log: Fix bug #72884 isCloneable() on SplFileObject should return false
 [2019-09-09 15:30 UTC] nikic@php.net
-Status: Verified +Status: Closed
 [2019-09-09 17:14 UTC] jhdxr@php.net
-Assigned To: +Assigned To: jhdxr
 [2019-09-09 17:14 UTC] jhdxr@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC