- Notifications
You must be signed in to change notification settings - Fork8k
Closed
Description
Description
The following code:
<?phpfunctionreadLinesFrom(string$filename):iterable{if (!is_readable($filename)) {thrownewException("File{$filename} does not exist or is not readable"); }$file =fopen($filename,'r');try {while (($line =fgets($file)) !==false) {yieldtrim($line); } }finally {fclose($file); }}$lines =iterator_to_array(readLinesFrom("/bad/file/path/1"));
when run multiple times withphp -dopcache.enable_cli=on -dopcache.optimization_level=0x0010 -derror_log=/proc/self/fd/2 myfile.php
Resulted in this output:
PHP Warning: Undefined variable $file in myfile.php on line 15Warning: Undefined variable $file in myfile.php on line 15PHP Fatal error: Uncaught Exception: File /bad/file/path/1 does not exist or is not readable in myfile.php:7Stack trace:#0 [internal function]: readLinesFrom('/bad/file/path/...')#1 myfile.php(19): iterator_to_array(Object(Generator))#2 {main}Next TypeError: fclose(): Argument #1 ($stream) must be of type resource, null given in myfile.php:15Stack trace:#0 myfile.php(15): fclose(NULL)#1 [internal function]: readLinesFrom('/bad/file/path/...')#2 myfile.php(19): iterator_to_array(Object(Generator))#3 {main} thrown in myfile.php on line 15Fatal error: Uncaught Exception: File /bad/file/path/1 does not exist or is not readable in myfile.php:7Stack trace:#0 [internal function]: readLinesFrom('/bad/file/path/...')#1 myfile.php(19): iterator_to_array(Object(Generator))#2 {main}Next TypeError: fclose(): Argument #1 ($stream) must be of type resource, null given in myfile.php:15Stack trace:#0 myfile.php(15): fclose(NULL)#1 [internal function]: readLinesFrom('/bad/file/path/...')#2 myfile.php(19): iterator_to_array(Object(Generator))#3 {main} thrown in myfile.php on line 15
But when run withphp -dopcache.enable_cli=on -dopcache.optimization_level=0 -derror_log=/proc/self/fd/2 myfile.php
I get this instead:
PHP Fatal error: Uncaught Exception: File /bad/file/path/1 does not exist or is not readable in myfile.php:7Stack trace:#0 [internal function]: readLinesFrom('/bad/file/path/...')#1 myfile.php(19): iterator_to_array(Object(Generator))#2 {main} thrown in myfile.php on line 7Fatal error: Uncaught Exception: File /bad/file/path/1 does not exist or is not readable in myfile.php:7Stack trace:#0 [internal function]: readLinesFrom('/bad/file/path/...')#1 myfile.php(19): iterator_to_array(Object(Generator))#2 {main} thrown in myfile.php on line 7
Slightly unsure if this is just another example of issue#8269 or not
PHP Version
PHP 8.3.16 and PHP 8.2.19
Operating System
Amazon Linux 2 and MacOS 15.2 (likely not relevant?)