diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 5be57bccbf852..99a0fcb989474 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -333,6 +333,9 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool return FAILURE; } + /* prevent closing the stream outside of SplFileObject */ + intern->u.file.stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE; + /* if (intern->u.file.zcontext) { //zend_list_addref(Z_RES_VAL(intern->u.file.zcontext)); diff --git a/ext/spl/tests/bug81691.phpt b/ext/spl/tests/bug81691.phpt new file mode 100644 index 0000000000000..597e37a9c8218 --- /dev/null +++ b/ext/spl/tests/bug81691.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #81691 fclose on SplFileObject stream +--FILE-- +fgets()); + +?> +--EXPECTF-- +Warning: fclose(): %d is not a valid stream resource in %s on line %d +string(6) "