Telling Intelephense to ignore undefined property |
Hi guys,
I just noticed in the recent Intelephense updates that CI3 models get flagged as potential problems. For example, the second line is flagged as "undefined property $this->messagesModel". What's the best way to tell it to ignore such errors? PHP Code: $this->load->model('Messages_model', 'messagesModel');
same problem,
i just add and save this ("intelephense.diagnostics.undefinedProperties": false), on file settings.json and then reload vscode, it works fine. PHP Code: /**
It's not uncommon for code analysis tools to flag certain constructs or syntax patterns as "potential problems" or errors, even if they are perfectly valid and functional in the context of your code. In this case, it seems that Intelephense is flagging the use of CI3 models as a potential problem.
To tell Intelephense to ignore such errors, you can use PHPDoc comments to provide explicit type hints and annotations for your code. For example, you can use the @property tag to define properties and their types for your models, like so: php /** * @property Messages_model $messagesModel */ class My_controller extends CI_Controller { public function some_method() { $this->load->model('Messages_model', 'messagesModel'); $this->messagesModel->some_fn(); } } This tells Intelephense that the $messagesModel property is an instance of the Messages_model class, and it should not flag any "undefined property" or other errors related to this property. Alternatively, you can also configure Intelephense to ignore certain files, folders, or patterns using the intelephense.files.exclude setting in your VSCode settings. For example, you can add the following pattern to ignore all CI3 models: json "intelephense.files.exclude": [ "**/application/models/*_model.php" ] This tells Intelephense to exclude all files with the pattern *_model.php in the application/models folder from analysis. Note that this approach may not be ideal if you still want to use Intelephense for other parts of your codebase, as it will disable analysis for all files matching this pattern. |
Welcome Guest, Not a member yet? Register Sign In |