CodeIgniter Forums
Need verbose logging in system/core/Model.php for "Cannot access empty property" bug - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Need verbose logging in system/core/Model.php for "Cannot access empty property" bug (/showthread.php?tid=64078)



Need verbose logging in system/core/Model.php for "Cannot access empty property" bug - Zelf - 01-12-2016

Please implement something along the following into system/core/Model.php. In large programs it can be a pain and next to impossible using php error logs alone to track down an empty property call. This will trace back to the exact line trying to access an empty key. Or at least add something other than a comment stating we have a typo somewhere. Thanks.

PHP Code:
public function __get($key)
 {
 if (!isset(
get_instance()->$key)) {
 
$e = new Exception();
 
$backTrace $e->getTraceAsString();

 
log_message('error'"Attempting to access empty key: {$backTrace}");
 }

 
// Debugging note:
 // If you're here because you're getting an error message
 // saying 'Undefined Property: system/core/Model.php', it's
 // most likely a typo in your model code.
 
return get_instance()->$key;
 }