From f49f709bad1911f8f7607148116a5dfc4cfd6787 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 20 Aug 2014 16:45:10 -0300 Subject: [PATCH 1/2] Recursive things are exclusively magical. ... Magically delicious, even. --- includes/tuque_wrapper.inc | 46 +++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 348ac60a..21a1d0b2 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -166,16 +166,21 @@ class IslandoraFedoraObject extends FedoraObject { public function __set($name, $value) { parent::__set($name, $value); - // XXX: Due to the structure of the code, we cannot use property_exists() - // (because many of the properties are declared in the class, and the magic - // triggers due them being NULLed), nor can we use isset() (because it is - // implemented as another magic function...). - $vars = get_object_vars($this); - while (isset($vars[$name])) { - $new_value = $this->$name; - unset($this->$name); - parent::__set($name, $new_value); + // Recursion only matters for magic properties... "Plain" properties cannot + // call other code in order to start recursing, and in fact we would get + // stuck looping with a "plain" property. + if ($this->propertyIsMagical($name)) { + // XXX: Due to the structure of the code, we cannot use property_exists() + // (because many of the properties are declared in the class, and the magic + // triggers due them being NULLed), nor can we use isset() (because it is + // implemented as another magic function...). $vars = get_object_vars($this); + while (isset($vars[$name])) { + $new_value = $this->$name; + unset($this->$name); + parent::__set($name, $new_value); + $vars = get_object_vars($this); + } } } @@ -430,16 +435,21 @@ class IslandoraFedoraDatastream extends FedoraDatastream { public function __set($name, $value) { parent::__set($name, $value); - // XXX: Due to the structure of the code, we cannot use property_exists() - // (because many of the properties are declared in the class, and the magic - // triggers due them being NULLed), nor can we use isset() (because it is - // implemented as another magic function...). - $vars = get_object_vars($this); - while (isset($vars[$name])) { - $new_value = $this->$name; - unset($this->$name); - parent::__set($name, $new_value); + // Recursion only matters for magic properties... "Plain" properties cannot + // call other code in order to start recursing, and in fact we would get + // stuck looping with a "plain" property. + if ($this->propertyIsMagical($name)) { + // XXX: Due to the structure of the code, we cannot use property_exists() + // (because many of the properties are declared in the class, and the magic + // triggers due them being NULLed), nor can we use isset() (because it is + // implemented as another magic function...). $vars = get_object_vars($this); + while (isset($vars[$name])) { + $new_value = $this->$name; + unset($this->$name); + parent::__set($name, $new_value); + $vars = get_object_vars($this); + } } } From 862bde2d64aeb47a8d51c32c37f3c963f8c5cefe Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 21 Aug 2014 09:31:06 -0300 Subject: [PATCH 2/2] Ermahgerd, lerns ter lerng. --- includes/tuque_wrapper.inc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 21a1d0b2..2f4ea1df 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -171,9 +171,9 @@ class IslandoraFedoraObject extends FedoraObject { // stuck looping with a "plain" property. if ($this->propertyIsMagical($name)) { // XXX: Due to the structure of the code, we cannot use property_exists() - // (because many of the properties are declared in the class, and the magic - // triggers due them being NULLed), nor can we use isset() (because it is - // implemented as another magic function...). + // (because many of the properties are declared in the class, and the + // magic triggers due them being NULLed), nor can we use isset() (because + // it is implemented as another magic function...). $vars = get_object_vars($this); while (isset($vars[$name])) { $new_value = $this->$name; @@ -440,9 +440,9 @@ class IslandoraFedoraDatastream extends FedoraDatastream { // stuck looping with a "plain" property. if ($this->propertyIsMagical($name)) { // XXX: Due to the structure of the code, we cannot use property_exists() - // (because many of the properties are declared in the class, and the magic - // triggers due them being NULLed), nor can we use isset() (because it is - // implemented as another magic function...). + // (because many of the properties are declared in the class, and the + // magic triggers due them being NULLed), nor can we use isset() (because + // it is implemented as another magic function...). $vars = get_object_vars($this); while (isset($vars[$name])) { $new_value = $this->$name;