Skip to content

Commit 1ac6b02

Browse files
jhdxrnikic
authored andcommitted
Fix bug #72884 isCloneable() on SplFileObject should return false
1 parent 8ead779 commit 1ac6b02

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ PHP NEWS
2525
. Fixed bug #78510 (Partially uninitialized buffer returned by
2626
sodium_crypto_generichash_init()). (Frank Denis, cmb)
2727

28+
- SPL:
29+
. Fixed bug #72884 (SplObject isCloneable() returns true but errs on clone).
30+
(Chu Zhaowei)
31+
2832
29 Aug 2019, PHP 7.2.22
2933

3034
- Core:

ext/spl/spl_directory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ static zend_object *spl_filesystem_object_clone(zval *zobject)
379379
intern->u.dir.index = index;
380380
break;
381381
case SPL_FS_FILE:
382-
zend_throw_error(NULL, "An object of class %s cannot be cloned", ZSTR_VAL(old_object->ce->name));
383-
return new_object;
382+
ZEND_ASSERT(0);
384383
}
385384

386385
intern->file_class = source->file_class;
@@ -3168,6 +3167,7 @@ PHP_MINIT_FUNCTION(spl_directory)
31683167
REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator);
31693168

31703169
memcpy(&spl_filesystem_object_check_handlers, &spl_filesystem_object_handlers, sizeof(zend_object_handlers));
3170+
spl_filesystem_object_check_handlers.clone_obj = NULL;
31713171
spl_filesystem_object_check_handlers.get_method = spl_filesystem_object_get_method_check;
31723172

31733173
#ifdef HAVE_GLOB

ext/spl/tests/bug72884.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #72884: isCloneable() on SplFileObject should return false
3+
--FILE--
4+
<?php
5+
$x=new SplFileObject(__FILE__);
6+
$r=new ReflectionObject($x);
7+
var_dump($r->isCloneable());
8+
9+
--EXPECT--
10+
bool(false)

ext/spl/tests/bug72888.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ try {
1212
var_dump($y);
1313
?>
1414
--EXPECTF--
15-
string(49) "An object of class SplFileObject cannot be cloned"
15+
string(60) "Trying to clone an uncloneable object of class SplFileObject"
1616

1717
Notice: Undefined variable: y in %sbug72888.php on line %d
1818
NULL

0 commit comments

Comments
 (0)