From a38413cddca8ac97c5ff9c35ba61cd7366110035 Mon Sep 17 00:00:00 2001 From: ahwelp Date: Wed, 1 May 2019 22:17:30 +0000 Subject: [PATCH] Magic get for empty objects --- src/ORM/Entity.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ORM/Entity.php b/src/ORM/Entity.php index 2de3bbf..9caf5f1 100755 --- a/src/ORM/Entity.php +++ b/src/ORM/Entity.php @@ -40,7 +40,14 @@ abstract class Entity { } $this->$property = $value; } - + + public function __get($key){ + if(!isset($this->$key)){ + return 0; + } + return $this->toArray()[$key]; + } + public function __toString() { if (isset($this->name)) { return $this->name; @@ -333,7 +340,9 @@ abstract class Entity { $objects[] = $object; } if (empty($objects)) { - return false; //new $this->classname; + //return false; //new $this->classname; + $className = static::class; + return new $className; } return $objects[0]; }