You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An "Abstract class SomeClass cannot be instantiated" appears when it shouldn't.
This seems a class-variable name collision bug. Changing the variable name, or reassigning it solves the issue.
How to reproduce
Create a php file with the following content and open it:
<?phpinterface MyClassInterface
{
publicfunctiondoSomething();
}
abstractclass MyClass
{
publicfunctiondoSomething()
{
}
abstractpublicfunctiondoSomethingElse();
}
class MySubClass extends MyClass implements MyClassInterface
{
publicfunctiondoSomethingElse()
{
}
}
class MyClassFactory
{
publicfunctionbuildObject(string$myClass): ?MyClass
{
if (class_exists($myClass) && is_subclass_of($myClass, MyClass::class)) {
// This causes "can not be instantiated error"$myObject = new$myClass(); // WORKS!// do something with $myObjectreturn$myObject; // WORKS!// Just using another variable name prevents the bug$myFQCN = $myClass;
$myObject = new$myFQCN();
// do something with $myObjectreturn$myObject;
}
returnnull;
}
// no errorpublicfunctioncreateObject(string$myFQCN): ?MyClass
{
if (class_exists($myFQCN) && is_subclass_of($myFQCN, MyClass::class)) {
$myObject = new$myFQCN();
// do something with $myObjectreturn$myObject;
}
returnnull;
}
}
$factory = newMyClassFactory();
$myObject1 = $factory->buildObject(MySubClass::class);
$myObject2 = $factory->createObject(MySubClass::class);
var_dump($myObject1);
var_dump($myObject2);
Did this work correctly in an earlier version?
No / Don't know
Operating System
mint/ubuntu 22.04
JDK
java-11-openjdk-amd64
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
Are you willing to submit a pull request?
No
The text was updated successfully, but these errors were encountered:
Apache NetBeans version
Apache NetBeans 18
What happened
An "Abstract class
SomeClass
cannot be instantiated" appears when it shouldn't.This seems a class-variable name collision bug. Changing the variable name, or reassigning it solves the issue.
How to reproduce
Create a php file with the following content and open it:
Did this work correctly in an earlier version?
No / Don't know
Operating System
mint/ubuntu 22.04
JDK
java-11-openjdk-amd64
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
Are you willing to submit a pull request?
No
The text was updated successfully, but these errors were encountered: