How to make autocomplete work in foreach php loop? (vscode, intellisense)



PHP Snippet 1:

/* @var $obj my_class_name */
$obj->obj_method();

PHP Snippet 2:

/** @var my_class_name $obj */
$obj->obj_method();

PHP Snippet 3:

/**
 * Returns the instance itself for Code completion
 * @return ClassName
 */
public static function self($instance) {
    return $instance;
}

PHP Snippet 4:

foreach ($list_of_objs as $obj) {
    $obj = ClassName::self($obj);
    $obj->obj_method()
}

PHP Snippet 5:

/** @var post $post */

PHP Snippet 6:

/** @var post $post */
foreach($res_class as $post)
{
   // you can use auto complete in vscode
   $post
}