peachpie icon indicating copy to clipboard operation
peachpie copied to clipboard

Compilation error: PHP4044: Type name could not be resolved.

Open cimperia opened this issue 5 years ago • 4 comments

During compilation, the following code fragment fails with : error PHP4044: Type name 'B' could not be resolved.

The expected behaviour is that the message “Class B does not exist!" gets displayed.

if (class_exists('B')) {
    class A extends B {
    }
}
else
    echo "Class B does not exist!";

cimperia avatar Jun 17 '20 09:06 cimperia

Thank you for the issue.

You are right, although as of now the compiler needs to know base types of all the defined classes.

Since the condition cannot be evaluated in compile-time, the compiler needs to compile the class A. We'll propose a feature on how to deal with this case in the future.

jakubmisek avatar Jun 18 '20 09:06 jakubmisek

Hello, are there any news on this issue? I just started with wordpress in .net core 3.1 and everything works fine. Now I wanted to install the bought Impreza theme and necessary plugins like us-core and ultimative_vc_addons but both ran into that problem. Class B belongs to WPBakery. WPBakery would be installed over the Wordpress Theme Site (if activated). Maybe this could be an additional problem.

MatthiasMertens avatar Aug 17 '21 16:08 MatthiasMertens

currently, there is only a workaround available;

Since the code is compiled, the class A and B must be known; otherwise, the code cannot be compiled.

The workaround is to wrap the construct in eval which effectively postpones the compilation up to the run time

eval('class A extends B {    }');

We're planning to deal with such cases in/after the version 1.1

jakubmisek avatar Aug 17 '21 16:08 jakubmisek

class A extends B { also class A implements B {

tharlab avatar Jun 13 '23 09:06 tharlab