]> granicus.if.org Git - php/commitdiff
Fix bug #72884 isCloneable() on SplFileObject should return false
authorCHU Zhaowei <me@jhdxr.com>
Sun, 8 Sep 2019 09:29:32 +0000 (09:29 +0000)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 9 Sep 2019 15:27:17 +0000 (17:27 +0200)
NEWS
ext/spl/spl_directory.c
ext/spl/tests/bug72884.phpt [new file with mode: 0644]
ext/spl/tests/bug72888.phpt

diff --git a/NEWS b/NEWS
index 91f3cf35d1d640885c8159c17449fff88b723802..a4f057be3d2a767bd90f26282d6c82b3f5c4b917 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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:
index 4f274641e8b99792656fb9fd963b81f47c614883..91ea2e026532f4d56816a06990ccecf7d74764f3 100644 (file)
@@ -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;
@@ -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
diff --git a/ext/spl/tests/bug72884.phpt b/ext/spl/tests/bug72884.phpt
new file mode 100644 (file)
index 0000000..178e0e1
--- /dev/null
@@ -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)
index 7d2fc6db08a039ec804796664e7f291f10fa2b39..d354490f8825519a887ec1c7299fbc393e5b3a6e 100644 (file)
@@ -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