How to deal with method not found in class warning for magically implemented methods?
Well, you can go to the preference menu, under Inspections, go to Undefined -> Undefined Method and check Downgrade severity if __magic methods are present.
That would make the flag less severe, (instead of Warning, as Info), which would still give you a green light on your document check.
There's nothing else I'm aware of aside from having @property
or @method
PHPDoc notations on the target class for every method that's likely to be used.
Get rid of magic method warning
You can turn off warnings for magically accessing properties in the following way:
- Go to File -> Settings -> Editor -> Inspections
- Go to PHP -> Undefined -> Undefined field
- Uncheck the box for "Notify about access to a field via magic method"
Check this page for more information
Method not found in class
PhpStorm cannot figure out what type your $this->cxn
field is. You can help by providing typehint via simple PHPDoc comment:
/** @var Database */
private $cxn; //database object
Is there a way to indicate that a class has magic methods defined for every method on another class?
The proper solution is to use supported @method
PHPDoc tags. This way it will also work in other editors/IDEs that support PHPDoc and understand such standard tag.
This approach requires every method to be listed separately. More on this in another StackOverflow question/answer: https://stackoverflow.com/a/15634488/783119.
In current PhpStorm versions you may use not-in-PHPDoc-specs (and therefore possibly PhpStorm-specific)
@mixin
tag.Adding @mixing className
in PHPDoc comment for your target class should do the job for you.
/**
* Class B
*
* @mixin A
*/
class B
{
Basically, @mixin
tag does what actual PHP's traits do.Please note that there is no guarantee that support for such tag will not be removed at some point in the future, although it's pretty unlikely.
Missing method implementations in PHP project
PHP has a few magic methods, and one of them is __call()
.
When you have an object that implements __call()
(by itself or by one of the parent classes), you may call an inaccessible method on it, and the __call()
method will be called instead. This happens, for example, when you call a private method from the outside, or when you call a method that was not defined in code.
When you use such calls to inaccessible methods, IDEs will most likely show a warning that the method does not exist, although the code itself will probably work at runtime. These warnings are quite annoying, so you can add a @method
tag to your class, and the IDE will know that this method exists, and will not show a warning.
So, to support the code that you got from someone, take a look at the __call()
method implementation. Be aware that this method may be implemented in one of the parent classes, so check them out as well.
Method not found on runtime
"Method not found" is a very specific error, which means a method it expected (i.e. was there at compile time) simply is not present. This usually means that the files you are deploying are different to what you think they are - specifically, I would wager that you are deploying the old version of the library (which lacks your additions).
Check the dlls deployed to the web-server against what you think they should be.
Related Topics
Difference Between Directoryiterator and Filesystemiterator
Number in the Top-Level Domain
Where to Store Database Login Credentials for a PHP Application
Setting PHP Enviromental Variable While Running Command Line Script
MySQL and Query to Satisfy on Same Column
Convert Multidimensional Objects to Array
How to Split a String into an Array of Unicode Characters in PHP
Codeigniter $This->Input->Post() Empty While $_Post Is Working Correctly
Use MySQL_Fetch_Array() with Foreach() Instead of While()
Login Event Handling in Laravel 5
PHP Splitting an Array into Two Arrays - Keys Array and Values Array
How to Get the Absolute Path to the Public_HTML Folder
What Is the Correct Format for a Blowfish Salt Using PHP's Crypt
Laravel - Validate File Size When PHP Max Upload Size Limit Is Exceeded