1

The properties are loaded dynamically in CodeIgniter.

How to let the editor know it should be allowed?

enter image description here

enter image description here

Jam
  • 386
  • 2
  • 13
  • It might be useful to mention why you don't want to declare this property, as it may make a difference to the answer. For instance, if you're using `__get` to define _specific_ fields dynamically, there may be ways to declare/document those field names. – IMSoP Nov 26 '19 at 12:14
  • If I declare these properties with `private $form_validation;`, it will instead show a similar error on the method call. `Method 'set_rules' not found in` – Jam Nov 26 '19 at 13:02
  • possible duplicate https://stackoverflow.com/questions/12670318/how-to-enable-auto-complete-in-phpstorm-for-codeigniter-framework – Atural Nov 26 '19 at 13:07
  • Not a duplicate. Different problem. – Jam Nov 27 '19 at 11:38

1 Answers1

1

If you know the full list of dynamic properties you're going to use, you can add them as @property docblock annotations on the class, in the format @property type name description.

The classic use case for this is where the class implements __get to lazy-load data, or in your case dependencies injected by the framework.

/**
 * @property FormValidation form_validation Form validation object injected by CodeIgniter
 */
class Example {
    public function foo() {
        $this->form_validation->set_rules('blah', 'blah', 'blah');
    }
}

Note that these magic properties are assumed to be inherited, and public, so the following will not show warnings:

// Using magic property in child class
class ExampleChild extends Example {
    public function somethingElse() {
        $this->form_validation->set_rules('something', 'else', 'entirely');
    }
}

// Using magic property from outside class
$foo = new Foo;
$fv = $foo->form_validation;
IMSoP
  • 89,526
  • 13
  • 117
  • 169