# Setzen einer Class-Variable aus einer Funktion heraus

**URL:** <https://forum.shopware.com/t/setzen-einer-class-variable-aus-einer-funktion-heraus/99697>\
**Category:** Shopware 6 (German)\
**Tags:** general, programming, templates--design, offizielle-shopware-\
**Created:** [14. Mai 2023 um 20:51 UTC](https://forum.shopware.com/t/setzen-einer-class-variable-aus-einer-funktion-heraus/99697 "2023-05-14T20:51:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shopwarer1638](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@shopwarer1638](https://forum.shopware.com/u/shopwarer1638)\
**Post date:** [14. Mai 2023 um 20:51 UTC](https://forum.shopware.com/t/setzen-einer-class-variable-aus-einer-funktion-heraus/99697/1 "2023-05-14T20:51:32Z")

</div>

Ich kann eine private Variable über \_\_construct setzen und abrufen,  
aber ich kann sie nicht von der Funktion mit $this-\> setzen:

```auto
class Subscriber implements EventSubscriberInterface
{
    private $currentProperty1;

	public function handleRequest(ProductListingCriteriaEvent $event): void
   {
   		// Here to get
        $array1 = array ($this->currentProperty1);
   }

    public function handleResult(ProductListingResultEvent $event)
    {
    	// Here to set
        $this->currentProperty1 = $currentProperty1;
    }
}

```

---

<div class="post-metadata">

**Author:** ![shopwarer1638](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@shopwarer1638](https://forum.shopware.com/u/shopwarer1638)\
**Post date:** [15. Mai 2023 um 08:10 UTC](https://forum.shopware.com/t/setzen-einer-class-variable-aus-einer-funktion-heraus/99697/2 "2023-05-15T08:10:55Z")

</div>

Wenn $currentProperty1 in \_\_construct,  
antwortet die URL nicht mehr.

Wenn $currentProperty1 aus \_\_construct entfernt wird,  
funktioniert die URL. Kennt jemand das Problem?

```auto
private $propertyGroupRepository;
private array $currentProperty1;

public function __construct(EntityRepositoryInterface $propertyGroupRepository, array $currentProperty1)
{
    $this->propertyGroupRepository = $propertyGroupRepository;
    $this->currentProperty1 = $currentProperty1;
}

```
