# Variable im Plugin zwischenspeichern

**URL:** <https://forum.shopware.com/t/variable-im-plugin-zwischenspeichern/14985>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [13. August 2013 um 20:17 UTC](https://forum.shopware.com/t/variable-im-plugin-zwischenspeichern/14985 "2013-08-13T20:17:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![keksterrrrr](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@keksterrrrr](https://forum.shopware.com/u/keksterrrrr)\
**Post date:** [13. August 2013 um 20:17 UTC](https://forum.shopware.com/t/variable-im-plugin-zwischenspeichern/14985/1 "2013-08-13T20:17:48Z")

</div>

Hallo allerseits, ich habe innerhalb eines Plugins 2 hooks und würde gerne eine Variable vom ersten hook zwischen speichern, um darauf in zweiten hook zugreifen zu können: ` public function install() { $this-\>subscribeEvent( "sAdmin::sGetPremiumShippingcosts::before", "beforeGetPremiumShippingcostsHook" ); $this-\>subscribeEvent( "sAdmin::sGetPremiumShippingcosts::after", "afterGetPremiumShippingcostsHook" ); } public function beforeGetPremiumShippingcostsHook( Enlight\_Hook\_HookArgs $arguments ) { // setze variable $variable = 123; // speicher irgendwie/irgendwo $this-\>variable = $variable; } public function afterGetPremiumShippingcostsHook( Enlight\_Hook\_HookArgs $arguments ) { // hole die variable $variable = $this-\>variable } ` Welche Möglichkeiten habe ich zum Speichern einer Variable? Ich könnte natürlich einfach alles in der $\_SESSION speichern - würde die Session allerdings ungerne mit Plugin Daten zumüllen. Kennt ihr eine geschickte Methode?! Vielen Dank & Gruß

---

<div class="post-metadata">

**Author:** ![Fabi](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@Fabi](https://forum.shopware.com/u/Fabi)\
**Post date:** [15. August 2013 um 15:49 UTC](https://forum.shopware.com/t/variable-im-plugin-zwischenspeichern/14985/2 "2013-08-15T15:49:46Z")

</div>

Moin moin, also wenn $this-\>variable nicht funktioniert, versuch mal self::$variable. Sollte in PHP auch ohne Deklaration funzen. Ansonsten die statische Variable in einer eigenen Methode. ` public function install() { $this-\>subscribeEvent( "sAdmin::sGetPremiumShippingcosts::before", "beforeGetPremiumShippingcostsHook" ); $this-\>subscribeEvent( "sAdmin::sGetPremiumShippingcosts::after", "afterGetPremiumShippingcostsHook" ); } public function variable($val = null) { static $buffer = null; if($val === null) { return $buffer; } else { $buffer = $val; } } public function beforeGetPremiumShippingcostsHook( Enlight\_Hook\_HookArgs $arguments ) { // setze variable $variable = 123; // speicher irgendwie/irgendwo $this-\>variable($variable); } public function afterGetPremiumShippingcostsHook( Enlight\_Hook\_HookArgs $arguments ) { // hole die variable $variable = $this-\>variable() } ` Ist natürlich ne extrem dreckige Variante, da die Methode variable() zwei Jobs erledigt. Erschwert anderen das rein denken. Deswegen gut dokumentieren.

---

<div class="post-metadata">

**Author:** ![keksterrrrr](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@keksterrrrr](https://forum.shopware.com/u/keksterrrrr)\
**Post date:** [16. August 2013 um 14:55 UTC](https://forum.shopware.com/t/variable-im-plugin-zwischenspeichern/14985/3 "2013-08-16T14:55:28Z")

</div>

Vielen Dank für deine Antwort. Da die hooks statisch per Klasse::hook\_Methode() aufgerufen werden, kann ich Werte definitiv nicht einfach mit $this im aktuellen Objekt speichern. Interessant ist natürlich der Ansatz die Variable statisch zu definieren. Prinzipiell müsste es doch auch so funktionieren: ` public static $variable; &nbsp; &nbsp;&nbsp;&nbsp; public function beforeGetPremiumShippingcostsHook( Enlight\_Hook\_HookArgs $arguments ) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; // speicher irgendwie/irgendwo &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; self::$variable = 123; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; public function afterGetPremiumShippingcostsHook( Enlight\_Hook\_HookArgs $arguments ) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; // hole die variable &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; $variable = self::$variable; &nbsp;&nbsp;&nbsp; }&nbsp; &nbsp; ` Habe ich noch nicht getestet - aber müsste funktionieren. Oder? Gruß
