From 9a4d7ff15bf8bf44570a1c186141958bd1b86c74 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 1 Sep 2013 19:57:54 +0200 Subject: [PATCH] Exception message when getting write-only property --- framework/yii/base/Component.php | 6 +++++- framework/yii/base/Object.php | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/framework/yii/base/Component.php b/framework/yii/base/Component.php index c1a2e04..cc3525e 100644 --- a/framework/yii/base/Component.php +++ b/framework/yii/base/Component.php @@ -57,7 +57,11 @@ class Component extends Object } } } - throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name); + if (method_exists($this, 'set' . $name)) { + throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name); + } else { + throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name); + } } /** diff --git a/framework/yii/base/Object.php b/framework/yii/base/Object.php index 9f22aba..adbab9c 100644 --- a/framework/yii/base/Object.php +++ b/framework/yii/base/Object.php @@ -70,6 +70,8 @@ class Object implements Arrayable $getter = 'get' . $name; if (method_exists($this, $getter)) { return $this->$getter(); + } elseif (method_exists($this, 'set' . $name)) { + throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name); } else { throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name); }