From b6925cbf8c451b4e742727bd0e94775d5030d972 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 21 Mar 2014 14:59:59 -0500 Subject: [PATCH] orm: Crash if accessing non-existent magic property --- include/class.dynamic_forms.php | 2 +- include/class.orm.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 0045b6a43..8c78c09b0 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -494,7 +494,7 @@ class DynamicFormEntry extends VerySimpleModel { function getForm() { if (!isset($this->_form)) { $this->_form = DynamicForm::lookup($this->get('form_id')); - if ($this->id) + if (isset($this->id)) $this->_form->data($this); } return $this->_form; diff --git a/include/class.orm.php b/include/class.orm.php index 289ddaef7..cdf255995 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -16,6 +16,8 @@ vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ +class OrmException extends Exception {} + class VerySimpleModel { static $meta = array( 'table' => false, @@ -46,6 +48,13 @@ class VerySimpleModel { $v = $this->ht[$field] = $class::lookup($this->ht[$j['local']]); return $v; } + throw new OrmException(sprintf('%s: %s: Field not defined', + get_class($this), $field)); + } + + function __isset($field) { + return array_key_exists($field, $this->ht) + || isset(static::$meta['joins'][$field]); } function set($field, $value) { @@ -86,7 +95,8 @@ class VerySimpleModel { // Construct related lists if (isset(static::$meta['joins'])) { foreach (static::$meta['joins'] as $name => $j) { - if (isset($j['list']) && $j['list']) { + if (isset($this->{$j['local']}) + && isset($j['list']) && $j['list']) { $fkey = $j['fkey']; $this->{$name} = new InstrumentedList( // Send Model, Foriegn-Field, Local-Id -- GitLab