From 85c550339ea685f4054f8600d2d5ba3185f39206 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Sat, 14 Jan 2012 14:52:31 +0100 Subject: [PATCH] Fix for magic property handling. Magic properties are trickier to handle because they may not be assignable by reference or they might be write-only or whatever. This patch tries to address these limits. --- Transmorph/Writer.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Transmorph/Writer.php b/Transmorph/Writer.php index 01ae951..58b0ac1 100644 --- a/Transmorph/Writer.php +++ b/Transmorph/Writer.php @@ -145,7 +145,22 @@ public function feed(&$node, $path, $value) $key = substr($pathNode, 1); - $this->feed($node->$key, $remainingPath, $value); + // Indirection to avoid problem with magic properties. + try + { + /* + * An exception may be raised in some conditions. For + * instance, this might be a write-only property or it might + * not have a value yet. + */ + $prop = $node->$key; + } + catch (Exception $e) + { + $prop = null; + } + $this->feed($prop, $remainingPath, $value); + $node->$key = $prop; } }