1--TEST-- 2Cannot serialize instance of Directory class constructed via Reflection. 3--FILE-- 4<?php 5 6$d = dir(__DIR__); 7try { 8 $cloned = clone $d; 9 $cloned_files = []; 10 while ($row = $cloned->read()){ 11 $cloned_files[] = $row; 12 } 13 var_dump(count($cloned_files)); 14 echo "Using original object:\n"; 15 $original_files = []; 16 while ($row = $d->read()){ 17 $original_files[] = $row; 18 } 19 var_dump(count($original_files)); 20} catch (\Throwable $e) { 21 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 22} 23 24?> 25--EXPECT-- 26Error: Trying to clone an uncloneable object of class Directory 27