Skip to content

Commit

Permalink
Fix bug #72884 isCloneable() on SplFileObject should return false
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdxr authored and nikic committed Sep 9, 2019
1 parent 8ead779 commit 1ac6b02
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ PHP NEWS
. Fixed bug #78510 (Partially uninitialized buffer returned by
sodium_crypto_generichash_init()). (Frank Denis, cmb)

- SPL:
. Fixed bug #72884 (SplObject isCloneable() returns true but errs on clone).
(Chu Zhaowei)

29 Aug 2019, PHP 7.2.22

- Core:
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ static zend_object *spl_filesystem_object_clone(zval *zobject)
intern->u.dir.index = index;
break;
case SPL_FS_FILE:
zend_throw_error(NULL, "An object of class %s cannot be cloned", ZSTR_VAL(old_object->ce->name));
return new_object;
ZEND_ASSERT(0);
}

intern->file_class = source->file_class;
Expand Down Expand Up @@ -3168,6 +3167,7 @@ PHP_MINIT_FUNCTION(spl_directory)
REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator);

memcpy(&spl_filesystem_object_check_handlers, &spl_filesystem_object_handlers, sizeof(zend_object_handlers));
spl_filesystem_object_check_handlers.clone_obj = NULL;
spl_filesystem_object_check_handlers.get_method = spl_filesystem_object_get_method_check;

#ifdef HAVE_GLOB
Expand Down
10 changes: 10 additions & 0 deletions ext/spl/tests/bug72884.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Bug #72884: isCloneable() on SplFileObject should return false
--FILE--
<?php
$x=new SplFileObject(__FILE__);
$r=new ReflectionObject($x);
var_dump($r->isCloneable());

--EXPECT--
bool(false)
2 changes: 1 addition & 1 deletion ext/spl/tests/bug72888.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
var_dump($y);
?>
--EXPECTF--
string(49) "An object of class SplFileObject cannot be cloned"
string(60) "Trying to clone an uncloneable object of class SplFileObject"

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

0 comments on commit 1ac6b02

Please sign in to comment.