I'm developing a PHP (v7.0.33) project using VScode (v1.56). I recently installed the VSCode's extension Intelephense (v1.7.1) and started to clean my code following Intelephense suggestions.

A set of classes inside my project has the following structure (function names are not real, but just to let you see that for each sublcass I have some function overrided from the superclass (those with the prefix baseFunction) and new functions specific for that subclass (those with the class acronym like fdmSpecificFunction):

enter image description here

According to the diagram, each DocumentSaver has an instance of a DocumentManager. The code where I create an instance of, for example, FatturaVenditaDocumentSaver is

$documentManager = new FatturaVenditaDocumentManager();
$documentSaver = new FatturaVenditaDocumentSaver($documentManager);
$documentSaver->baseFunction1();

Consider the following code inside FatturaVenditaDocumentSaver:

public function baseFunction1() {
    parent::baseFunction1();
    $this->documentManager->fvdmSpecificFunction1();
}

This is a common implementation in OOP, using polymorphism and dynamic binding: having created the instance of FatturaVenditaDocumentSaver with a document manager instantiated from FatturaVenditaDocumentManager, the call $documentSaver->baseFunction1() will execute the code implemented in FatturaVenditaDocumentSaver and, inside it, will correctly execute the code inside fvdmSpecificFunction1() implemented in FatturaVenditaDocumentManager.

The problem is that Intelephense, as fvdmSpecificFunction is not defined in BaseDocumentManager, gives me the error "Undefined method 'fvdmSpecificFunction1'. Intelephense (1013)".

Is there a way to let Intelephense understand the real implementation of my code (considering that Intelephense parse all my PHP code)? I'd like to avoid to disable the Intelliphense's "undefined method" check and I don't like to add an empty fvdmSpecificFunction1 in BaseDocumentManager as is not consistent with the project's logic.

Thank you in advance for your help.

1

There are 1 answers

2
Ma3x On BEST ANSWER

Solution found!

I had just to add the @property hint before the class block, specifying the type of the object $documentManager.

/**
 * @property    FatturaVenditaDocumentManager   $documentManager
 */
class FatturaVenditaSaver extends FatturaSaver {
    public function baseFunction1() {
        parent::baseFunction1();
        $this->documentManager->fvdmSpecificFunction1();
    }
}

In this way, Intelephense understands the real class related to that object.