Hello. I came across a case where the code analyzer is not showing a call to an unknown function error for a call to a function which is not declared/defined in the class or parent classes. If there are several child classes that do implement the function, the analyzer picks seemingly the first class it comes across but not always. It does not require a declaration of the function in the same class or at least a check of instanceof or is_a child class as expected. And Ctrl/CMD clicking the function sometimes brings me to a different class that implemented it.
I'm using a new VS Code window attached to a Docker container with PHP 7.4 installed using PHP extension v1.41.14263.
Originally, I was getting no errors at all regarding unknown functions or classes, but it was because PHP was not installed in the environment, so the extension was not working despite claiming to fallback to a default PHP. I attached to one of my containers that have PHP and resolved that issue.
Please see this code and screenshot and advise:
<?php
abstract class MyAbstractClass
{
public function test()
{
$this->testActual($unassignedVar);
// Should show unknown function error, but it doesn't
// Hovering or ctrl/cmd+clicking this shows a child class implementation at random
$this->testActualDefinedInChild();
}
// Both of these two declarations should be required to alleviate the
// expected unknown function
// errors above in case of a missing implementation:
// abstract public function testActual();
// abstract public function testActualDefinedInChild();
}
class MyChildClass extends MyAbstractClass
{
public function testActualDefinedInChild()
{
echo "hello from MyChildClass\n";
}
}
class MySecondChildClass extends MyAbstractClass
{
public function testActualDefinedInChild()
{
echo "hello from MySecondChildClass\n";
}
}
class MyThirdChildClass extends MyAbstractClass
{
// testActualDefinedInChild() is not implemented here so MyAbstractClass->test()
// would encounter an unknown function error
}
Thanks!