Re: [Initial Feedback] Typed Arrays

From: Date: Thu, 27 Jun 2024 19:41:35 +0000
Subject: Re: [Initial Feedback] Typed Arrays
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Could someone please spare a moment to give me karma so I can open an RFC? 
I greatly appreciate your time. My username is: wookieetyler

Derick Rethans commit inspired me to start looking at the source code in more depth. 
I got started on this branch <https://github.com/php/php-src/compare/master...RichardTMiles:php-src:arrayTypes>
last night, I focused on the zend_language_parser.y. I think I got that figured out, and not I need
to adjust the functions it touches (zend_ast_create_decl and zend_ast_create).
I might call myself a very seasoned n00b here, so my main goal is to get it working.

interface_declaration_statement:
               T_INTERFACE { $<num>$ = CG(zend_lineno); }
               T_STRING interface_extends_list backup_doc_comment '{' class_statement_list
'}'
                      { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2,
$5, zend_ast_get_str($3), NULL, $4, $7, NULL, NULL); }
               | T_INTERFACE { $<num>$ = CG(zend_lineno); }
               T_STRING interface_extends_list backup_doc_comment '[' array_statement_list
']'
                      { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2,
$4, zend_ast_get_str($2), NULL, $3, $6, NULL, NULL); }
;


Then for casting: 

expr:
...
|       type_without_static expr
                       { $$ = zend_ast_create(ZEND_AST_CAST, $2, $4); }
|       '(' type_expr_without_static_or_nullable ')' expr
               { $$ = zend_ast_create(ZEND_AST_CAST, $2, $4); }
|       '(' expr ')' {
               $$ = $2;
               if ($$->kind == ZEND_AST_CONDITIONAL) $$->attr =
ZEND_PARENTHESIZED_CONDITIONAL;
        }
|       new_expr { $$ = $1; }
...


I should also point out that the syntax I posed yesterday was a bit incorrect as I extended an
interface using the implements keyword.


>> interface iArrayA ['a' => string ]
>> interface iArrayB implements iArrayA ['b' => string, 'c' =>
>> ?string ]

It should actually read:

interface iArrayA [ ‘a’ => string ]
interface iArrayB extends iArrayA [ ‘b’ => string, ‘c’ => ?string]


P.s. I also started a draft for the addition of the apache_connection_stream function
https://github.com/php/php-src/pull/14047
and would like to create an RFC for that as well.


Best,
Richard Miles



Thread (39 messages)

« previous php.internals (#123957) next »