diff --git a/src/Traits/EntityTrait.php b/src/Traits/EntityTrait.php index 1de9309..983069e 100644 --- a/src/Traits/EntityTrait.php +++ b/src/Traits/EntityTrait.php @@ -16,7 +16,7 @@ public function __get(string $key) // First check the framework's version $result = parent::__get($key); - if ($result !== null) + if ($result !== null || array_key_exists($key, $this->attributes)) { return $result; } diff --git a/tests/entity/MagicTest.php b/tests/entity/MagicTest.php index 79ea93a..7584016 100644 --- a/tests/entity/MagicTest.php +++ b/tests/entity/MagicTest.php @@ -23,6 +23,18 @@ public function testGetIgnoresUnmatched() { $this->assertNull($this->factory->racecars); } + + public function testGetRespectsNull() + { + $machine = new Machine([ + 'factory_id' => 1, + 'factory' => null, + ]); + + $result = $machine->factory; + + $this->assertNull($result); + } public function testRequiresProperties() {