File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -294,8 +294,14 @@ public function __get(string $key)
294294 {
295295 $ result = $ this ->castAs ($ result , $ this ->_options ['casts ' ][$ key ]);
296296 }
297+
298+ if (! isset ($ result ) && ! property_exists ($ this , $ key ))
299+ {
300+ throw EntityException::forTryingToAccessNonExistentProperty ($ key , get_called_class ());
301+ }
297302
298303 return $ result ;
304+
299305 }
300306
301307 //--------------------------------------------------------------------
Original file line number Diff line number Diff line change 1+ <?php namespace CodeIgniter \Exceptions ;
2+
3+ /**
4+ * Entity Exceptions.
5+ */
6+
7+ class EntityException extends AlertError
8+ {
9+
10+ /**
11+ * Error code
12+ *
13+ * @var integer
14+ */
15+ protected $ code = 3 ;
16+
17+ public static function forTryingToAccessNonExistentProperty (string $ property , string $ on )
18+ {
19+ throw new static (lang ('Entity.tryingToAccessNonExistentProperty ' , [$ property , $ on ]));
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * CLI language strings.
5+ *
6+ * @package CodeIgniter
7+ * @author CodeIgniter Dev Team
8+ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/)
9+ * @license https://opensource.org/licenses/MIT MIT License
10+ * @link https://codeigniter.com
11+ * @filesource
12+ *
13+ * @codeCoverageIgnore
14+ */
15+
16+ return
17+ [
18+ 'tryingToAccessNonExistentProperty ' => 'Trying to access non existent property {0} of {1} '
19+ ];
You can’t perform that action at this time.
0 commit comments