In Layout class, a set of interfaces is implemented: JsonSerializable and ArrayAccess.
PHP 8 method signatures need to define the methods parameters types and return types in order to comply with these interfaces.
For instance, the method:
public function offsetSet($offset, $value)
It should look like:
public function offsetSet(mixed $offset, mixed $value): void
Otherwise, we get this warning in logs:
Return type of Whitecube\NovaFlexibleContent\Layouts\Layout::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/henriquespin/Code/orca/vendor/whitecube/nova-flexible-content/src/Layouts/Layout.php on line 493
PHP versions before 8.0 parse the attribute syntax as a code comment and do not cause any syntax errors. Adding #[\ReturnTypeWillChange] attribute to a class method does not cause any issues, but omits the deprecation notice in PHP 8.1.
This is the first built-in attribute added to PHP.
class Layout implements ArrayAccess {
#[\ReturnTypeWillChange]
public function offsetGet(mixed $offset) {}
// ...
}
In Layout class, a set of interfaces is implemented: JsonSerializable and ArrayAccess.
PHP 8 method signatures need to define the methods parameters types and return types in order to comply with these interfaces.
For instance, the method:
It should look like:
Otherwise, we get this warning in logs:
Return type of Whitecube\NovaFlexibleContent\Layouts\Layout::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/henriquespin/Code/orca/vendor/whitecube/nova-flexible-content/src/Layouts/Layout.php on line 493
PHP versions before 8.0 parse the attribute syntax as a code comment and do not cause any syntax errors. Adding #[\ReturnTypeWillChange] attribute to a class method does not cause any issues, but omits the deprecation notice in PHP 8.1.
This is the first built-in attribute added to PHP.
https://php.watch/versions/8.1/ReturnTypeWillChange