22.02.2022・TechStuff
22.02.2022・TechStuff

Shopware 6: Cannot access private property Namespace\Class::$property

Fabian Blechschmidt

You have this error? More trace is at the end of the post.

The properties of your Entity need to be protected.

// WRONG.
class SlotExtensionEntity extends Entity
{
    use EntityIdTrait;

    private int $slotId;
    private int $ticketsBeforeWaitlist;
    private SlotEntity $slot;
// [...]
}
// Correct.
class SlotExtensionEntity extends Entity
{
    use EntityIdTrait;

    protected int $slotId;
    protected int $ticketsBeforeWaitlist;
    protected SlotEntity $slot;
// [...]
}
"errors": [
        {
            "code": "0",
            "status": "500",
            "title": "Internal Server Error",
            "detail": "Cannot access private property WinkelwagenEvents\\Entities\\Slot\\SlotExtensionEntity::$slot",
            "meta": {
                "trace": [
                    {
                        "file": "/var/www/html/vendor/shopware/core/Framework/DataAbstractionLayer/Entity.php",
                        "line": 82,
                        "function": "__get",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Entity",
                        "type": "->",
                        "args": [
                            "slot"
                        ]
                    },
                    {
                        "file": "/var/www/html/vendor/shopware/core/Framework/Api/Serializer/JsonApiEncoder.php",
                        "line": 89,
                        "function": "get",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Entity",
                        "type": "->",
                        "args": [
                            "slot"
                        ]
                    },
[...]