I read various articles claiming that now php-8 also is strongly type language https://medium.com/codex/php-became-strongly-typed-66f2b2ae917. Since I work with typescript, i was looking for same IDE experience but when I recently started to working on WordPress, ad I found that mostly associative arrays are used instead of objects for passing arguments in WordPress method like
register_post_type('event',array(
'show_in_rest'=>true,
'supports'=>array('title','editor','excerpt'),
'rewrite'=>array('slug'=>'events'),
'has_archive'=>true,
'public'=>true,
'labels'=>array(
'name'=>'Events',
'add_new_item'=>"Add New Event",
'edit_item'=>"Edit Event",
'all_items'=>"All Events",
'singular_name'=>'Event'
),
'menu_icon'=>'dashicons-calendar'
));
Since in java and typescript i mostly use object to pass data thus ide provide very nice hinting system. Now for php-8 arrays, IDE provide no auto-completion like in typescript or in java. Is there a way to get same type hint experience with php as it is in typescript or in java.
CodePudding user response:
WordPress has been around for almost two decades, long before php 8. Many sites still run on php 5.6 (!!!). Sad to say, it uses these associative arrays rather than strongly typed objects for its functions requiring data-structure parameters.