@@ -340,7 +340,18 @@ static inline void ast_update_property_long(zval *object, zend_string *name, zen
340
340
ast_update_property (object , name , & value_zv , cache_slot );
341
341
}
342
342
343
- static zend_ast * get_ast (zend_string * code , zend_arena * * ast_arena , char * filename ) {
343
+ static zend_ast * get_ast (zend_string * code , zend_arena * * ast_arena , zend_string * filename ) {
344
+ #if PHP_VERSION_ID >= 80100
345
+ if (filename ) {
346
+ return zend_compile_string_to_ast (code , ast_arena , filename );
347
+ } else {
348
+ zend_ast * ast ;
349
+ filename = zend_string_init ("string code" , sizeof ("string code" ) - 1 , 0 );
350
+ ast = zend_compile_string_to_ast (code , ast_arena , filename );
351
+ zend_string_release_ex (filename , 0 );
352
+ return ast ;
353
+ }
354
+ #else
344
355
zval code_zv ;
345
356
zend_bool original_in_compilation ;
346
357
zend_lex_state original_lex_state ;
@@ -352,7 +363,7 @@ static zend_ast *get_ast(zend_string *code, zend_arena **ast_arena, char *filena
352
363
CG (in_compilation ) = 1 ;
353
364
354
365
zend_save_lexical_state (& original_lex_state );
355
- zend_prepare_string_for_scanning (& code_zv , filename );
366
+ zend_prepare_string_for_scanning (& code_zv , filename ? filename -> val : "string code" );
356
367
CG (ast ) = NULL ;
357
368
CG (ast_arena ) = zend_arena_create (1024 * 32 );
358
369
LANG_SCNG (yy_state ) = yycINITIAL ;
@@ -373,6 +384,7 @@ static zend_ast *get_ast(zend_string *code, zend_arena **ast_arena, char *filena
373
384
zval_dtor (& code_zv );
374
385
375
386
return ast ;
387
+ #endif
376
388
}
377
389
378
390
/* Returns whether node->attr (i.e. flags) is used by this node kind. Not to be confused with php 8.0's attributes. */
@@ -1106,7 +1118,7 @@ PHP_FUNCTION(parse_file) {
1106
1118
code = ZSTR_EMPTY_ALLOC ();
1107
1119
}
1108
1120
1109
- ast = get_ast (code , & arena , filename -> val );
1121
+ ast = get_ast (code , & arena , filename );
1110
1122
if (!ast ) {
1111
1123
zend_string_free (code );
1112
1124
return ;
@@ -1136,7 +1148,7 @@ PHP_FUNCTION(parse_code) {
1136
1148
return ;
1137
1149
}
1138
1150
1139
- ast = get_ast (code , & arena , filename ? filename -> val : "string code" );
1151
+ ast = get_ast (code , & arena , filename );
1140
1152
if (!ast ) {
1141
1153
return ;
1142
1154
}
0 commit comments