Search code examples
phpphpstormphpdoctype-hinting

PhpStorm - PHPDoc "any" type for parameters


I am coming from a strictly typed programming language, which has a type named "ANY".

Because PHP is loosely coupled, I would need for my PhpDoc some sort of type hinting saying that the variable, parameter or return value can be of any type. At the moment I have to write something like:

@var string|int|bool|array|object $someVariable

It would make my life easier and the code would be much easier to read if I could write instead:

@var any $someVariable

I am actually having this problem in many cases - more than 20-30 times by now in the last months, since I use PhpStorm, which is showing me warnings that some other kind of parameter type is expected for some method, either because I forgot to put it explicitly in the list of types or because I am using code written in Eclipse, which did not show any warnings for my self-proclaimed "any" type.

My question: is there a way to tell PhpStorm that when I say any I actually mean string|any|bool|array|object or is there some other type hint which says that? I am also curious if I am the only one having this issue or if there are some others working like this.


Solution

  • You should use "mixed" for that. Also with PHP7.0 there is actual type hinting for parameters and return values.