we can have an autocomplete in PHP Editors for a class like:
<?php
/**
* Class Controller
* @property foo foo
*/
class Controller {
public function bar() {
$this->foo-> // autocomplete here
}
}
class foo() {
}
but if i want an auto complete for a magic method like __call
how is that possible
example below:
<?php
Class Controller {
public function __call($function, $arguments) {
if($function == 'foo') {
// some logic here
}
}
}
Class Home extends Controller {
public function somefunction() {
$this-> // should have an autocomplete of foo
}
}
any idea how could this be achieved to configure auto-complete in PHP Editors
I use PHP-Storm if there is something specific
PHP magic methods are special methods in a class. The magic methods override the default actions when the object performs the actions. By convention, the names of magic methods start with a double underscore ( __ ). And PHP reserves the methods whose names start with a double underscore ( __) for magic methods.
But you can use utilize the __call () magic method to make the code shorter. The following defines the Str class that uses the __call () magic method: How it works. The $functions property store the mapping between the methods and built-in string function.
When you call a method on an object of the Str class and that method doesn’t exist e.g., length (), PHP will invoke the __call () method. The __call () method will raise a BadMethodCallException if the method is not supported. Otherwise, it’ll add the string to the argument list before calling the corresponding function.
The user is writing text in a highly structured language, such as code. There are many implementations of AutoComplete, including Visual Studio Intellisense, Google Suggest, Word Processors, and in the last few years it’s become quite ubiquitous on mobile devices.
you can use @method
phpdoc tag to get autocomplete for magic methods
here is a code example for you:
<?php
/**
* Class Controller
* @method mixed foo() foo($parametersHere) explanation of the function
*/
Class Controller {
public function __call($function, $arguments) {
if($function == 'foo') {
// some logic here
}
}
}
This should work well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With