Magic Method Support for PHP

I've officially switched over to PhpStorm as my primary PHP IDE. I'm loving many of its features, it's excellent. I love the fact that it can detect the usage of undeclared object vars and methods... But this can pose a problem in some cases. For example:

 $this->dom = new DOMDocument;
 $this->dom->formatOutput = true;

PhpStorm is marking formatOutput as an undefined field. But it's built-in to PHP. However that's not the only issue, that's actually a minor one. One of my biggest issues is that many codebases I work on use PHP's magic methods, specifically __get(), __set() and __call(). PhpStorm doesn't appear to support those because, for example:

$zend_console_getopt = new Zend_Console_Getopt(array(
     "help|h" => "Show this help message"
if ($zend_console_getopt->help)

It's marking help as an undefined field. Now I understand that it would be a huge task for PhpStorm to be able to autodetect this kind of thing, but it should at least mark undefined fields and methods in classes that have implementations of the magic methods differently, perhaps as a separate kind of inspection. Ideas?

Oh, nearly forgot to mention. Support for setting undefined fields in an stdClass object shouldn't be marked, but maybe it can detect when they haven't been declared yet?


And something else I've just discovered...

I'm using Smarty in one project and have extended it, like so:

class SmartyMain extends Smarty

Then I use this:

$smarty = new SmartyMain;

It's marking the assign function as non-defined...

You can use the PHPDoc @property comments:

However, it seems that phpStorm does not support the mention of a variable-type


>However, it seems that phpStorm does not support the mention of a variable-type :(
Please elaborate on this PhpStorm supports @property tags just as described in the page you've pointed at AFAIK


I've found the @method described in phpDoc manual useful in solving similar problems in 2017 version of IntelliJ IDEA (and others mentioned similar results for PHPStorm - also later versions, IDEA included).

@method works for __call() while the @property mentioned in a 2010 post above works for __get() and __set() magic methods.


Please sign in to leave a comment.