Magic get for empty objects

This commit is contained in:
ahwelp
2019-05-01 22:17:30 +00:00
parent bacce810a1
commit a38413cddc
+10 -1
View File
@@ -41,6 +41,13 @@ abstract class Entity {
$this->$property = $value; $this->$property = $value;
} }
public function __get($key){
if(!isset($this->$key)){
return 0;
}
return $this->toArray()[$key];
}
public function __toString() { public function __toString() {
if (isset($this->name)) { if (isset($this->name)) {
return $this->name; return $this->name;
@@ -333,7 +340,9 @@ abstract class Entity {
$objects[] = $object; $objects[] = $object;
} }
if (empty($objects)) { if (empty($objects)) {
return false; //new $this->classname; //return false; //new $this->classname;
$className = static::class;
return new $className;
} }
return $objects[0]; return $objects[0];
} }