-
-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Describe the bug
I have this error in my script.
Typed property Butschster\Head\MetaTags\Meta::$config must not be accessed before initialization
this is how the code is organized in my project:
the controller (actually the trait, but it doesn't make sense here):
use Butschster\Head\Facades\Meta;
use Butschster\Head\Packages\Entities\OpenGraphPackage;
use Butschster\Head\Packages\Package;
...
$meta = new Package('default');
$og = new OpenGraphPackage('default_og');
$meta->setTitle('JohnDoe&Co') // <-- ERROR IS THERE
->prependTitle($title);
$og->setTitle(
$title.' '.
config('meta_tags.title.separator').' JohnDoe&Co'
);
$og->setSiteName('JohnDoe&Co');
Meta::replacePackage($meta);
Meta::replacePackage($og);
it's clearly seen that I instantiate an instance of \Butschster\Head\Packages\Package, which is okay, and it extends the \Butschster\Head\MetaTags\Meta which has a different declaration of constructor where the $config variable is expected.
apparently the thing is Package doesn't call the parent's constructor and that's why the private promoted property $config in Meta lefts undefined.
Environment:
- PHP: 8.3.6
- Laravel: 11.26.0
- Package: 3.1.1
Possible solution
The easiest fix is to declare the $config variable in a regular way (not promoted), so the code looks like this
class Meta implements MetaInterface, \Stringable
...
private ?Repository $config = null;
public function __construct(
protected Manager $packageManager,
?Repository $config = null,
) {
$this->config = $config;
$this->initPlacements();
}
...
thanks for your open-source development
