diff --git a/system/Entity.php b/system/Entity.php index b2fbc67d3630..6a7472a55f93 100644 --- a/system/Entity.php +++ b/system/Entity.php @@ -294,8 +294,14 @@ public function __get(string $key) { $result = $this->castAs($result, $this->_options['casts'][$key]); } + + if(! isset($result) && ! property_exists($this, $key)) + { + throw EntityException::forTryingToAccessNonExistentProperty($key, get_called_class()); + } return $result; + } //-------------------------------------------------------------------- diff --git a/system/Exceptions/EntityException.php b/system/Exceptions/EntityException.php new file mode 100644 index 000000000000..40e301717c87 --- /dev/null +++ b/system/Exceptions/EntityException.php @@ -0,0 +1,22 @@ + 'Trying to access non existent property {0} of {1}' +];