@@ -62,33 +62,37 @@ bool File::compile()
62
62
if (_opcodes) return _opcodes->valid ();
63
63
64
64
// we are going to open the file
65
- zend_file_handle fileHandle ;
65
+ zend_file_handle filehandle ;
66
66
67
67
#if PHP_VERSION_ID < 80100
68
+
68
69
// open the file
69
70
if (zend_stream_open (ZSTR_VAL (_path), &fileHandle) == FAILURE) return false ;
71
+
70
72
#else
71
- /* *
72
- * zend_stream_open now only accepts the fileHandle object
73
- * Filename must now be set through the object path.
74
- */
75
- fileHandle.filename = _path;
76
73
77
- // open the file
78
- if (zend_stream_open (&fileHandle) == FAILURE) return false ;
74
+ // since php 8 (or 8.1? - this has not been checked), zend_stream_open just takes the file-handle, and we must associate it first with a filename
75
+ zend_stream_init_filename_ex (&filehandle, _path);
76
+
77
+ // the stream if supposed to be open by now
78
+ if (zend_stream_open (&filehandle) == FAILURE) return false ;
79
+
79
80
#endif
80
81
81
- // make sure the path name is stored in the handle (@todo: is this necessary? do we need the copy?)
82
- if (!fileHandle.opened_path ) fileHandle.opened_path = zend_string_copy (_path);
82
+ // make sure the path name is stored in the handle (@todo: is this necessary? do we need the copy,
83
+ // this was copied from zend_execute.c, maybe deals with case when opened_path is not set for
84
+ // special types of files that are correctly opened, but that do not expose path-info, while this info
85
+ // is still needed by the subsequent zend_compile_file() call for error messages?)
86
+ if (!filehandle.opened_path ) filehandle.opened_path = zend_string_copy (_path);
83
87
84
88
// we need temporary compiler options
85
89
CompilerOptions options (ZEND_COMPILE_DEFAULT);
86
90
87
91
// create the opcodes
88
- _opcodes.reset (new Opcodes (zend_compile_file (&fileHandle , ZEND_INCLUDE)));
92
+ _opcodes.reset (new Opcodes (zend_compile_file (&filehandle , ZEND_INCLUDE)));
89
93
90
94
// close the file handle
91
- zend_destroy_file_handle (&fileHandle );
95
+ zend_destroy_file_handle (&filehandle );
92
96
93
97
// done
94
98
return _opcodes->valid ();
@@ -133,9 +137,6 @@ Value File::execute()
133
137
// try compiling the file
134
138
if (!compile ()) return nullptr ;
135
139
136
- // add the entry to the list of included files
137
- zend_hash_add_empty_element (&EG (included_files), _path);
138
-
139
140
// execute the opcodes
140
141
return _opcodes->execute ();
141
142
}
@@ -152,6 +153,9 @@ Value File::once()
152
153
// check if this file was already included
153
154
if (zend_hash_exists (&EG (included_files), _path)) return nullptr ;
154
155
156
+ // add the entry to the list of included files
157
+ zend_hash_add_empty_element (&EG (included_files), _path);
158
+
155
159
// execute the file
156
160
return execute ();
157
161
}
0 commit comments