bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.6k stars 94 forks source link

Array element type lost when assigning to array #688

Closed juneszh closed 4 years ago

juneszh commented 5 years ago

I packaged a DB class and return the instantiation from class medoo, but there isn't any auto-complete suggestion from medoo when i coding use DB. Is that anything wrong in my code?

2019-09-18 205029

2019-09-18 205111

KapitanOczywisty commented 5 years ago

With array you need to specify return type:

    public static function init($source = 'master') : Medoo
    { /*...*/ }

Or:

    /**
     * @return Medoo
     */
    public static function init($source = 'master')
    { /*...*/ }

Without array extension should be able to recognize return type on its own, but when you explicitly write types there is greater chance to catch bugs and prevent unexpected behavior.

KapitanOczywisty commented 5 years ago

@bmewburn There is something wrong with type detection: when new instance is added to array then mysqli type becomes mixed

image image

juneszh commented 5 years ago

With array you need to specify return type:

  public static function init($source = 'master') : Medoo
  { /*...*/ }

Or:

  /**
   * @return Medoo
   */
  public static function init($source = 'master')
  { /*...*/ }

Without array extension should be able to recognize return type on its own, but when you explicitly write types there is greater chance to catch bugs and prevent unexpected behavior.

Thx! It's helpful for me.

bmewburn commented 5 years ago

It appears to be generalising the property type to array which shouldn't be the case.