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
I should be able to have two different classes that extend the Widget class that use the same names
Actual Behavior
I just upgraded from PHP 7.4 to 8.2 and I'm now having errors thrown when using register_widget() on two classes that both have a field named image. It gives the error:
Fatal error: Uncaught Exception: Field name "_image" already registered
in /bla/bla/bla/carbon-fields/core/Exception/Incorrect_Syntax_Exception.php on line 22
I believe that this functionality changed in PHP 8.1 such that $registered_field_names now contains all registered field names from that have ever gone through this method instead of being scoped to only the registered field names for the current class.
The following bit of code can be used to show the difference between PHP versions:
class Base {
publicfunctionsetThing($thing) {
static$things = [];
$things[] = $thing;
var_dump($things);
}
}
class A extends Base {
publicfunctionsetSomeThing()
{
$this->setThing('1');
}
}
class B extends Base {
publicfunctionsetSomeThing()
{
$this->setThing('a');
}
}
$a = newA();
$a->setSomeThing();
$b = newB();
$b->setSomeThing();
If you run this using php 7.4 you get the following output:
Version
Expected Behavior
I should be able to have two different classes that extend the Widget class that use the same names
Actual Behavior
I just upgraded from PHP 7.4 to 8.2 and I'm now having errors thrown when using register_widget() on two classes that both have a field named
image
. It gives the error:Which in the callstack is being thrown from:
Comments
The issue is this bit of code here:
specifically
static $registered_field_names = array();
I believe that this functionality changed in PHP 8.1 such that
$registered_field_names
now contains all registered field names from that have ever gone through this method instead of being scoped to only the registered field names for the current class.The following bit of code can be used to show the difference between PHP versions:
If you run this using php 7.4 you get the following output:
But with 8.2 (I'm assuming 8.1 as well but I haven't had time to test it)
The text was updated successfully, but these errors were encountered: