title: lazy load models and libraries in CI 3 __get magic method of controller
body: <p>I am attempting to write a lazy loader for models + libraries in CI 3.0.4</p>
  
  <p>I am trying to get the following as described in:</p>
  
  <p><a href="https://stackoverflow.com/questions/17579449/model-library-lazy-load-in-codeigniter">Model/library lazy load in CodeIgniter</a></p>
  
  <p>This code seems to be for CI version 2 and when I tried to apply it to CI version 3.0.4 I get the following errors.</p>
  
  <pre><code>Severity: Notice
  
  Message: Indirect modification of overloaded property Items::$benchmark has no effect
  
  Filename: core/Controller.php
  
  Line Number: 75
  
  
  Fatal error: Cannot assign by reference to overloaded object in /Applications/MAMP/htdocs/phppos/PHP-Point-Of-Sale/system/core/Controller.php on line 75
  </code></pre>
  
  <p>Here is what I did:</p>
  
  <ol>
  <li><p>Create file application/core/MY_Controller.php</p></li>
  <li><p>Create the following code:</p>
  
  <p>
  
  <pre><code>    //Lazy load based on https://stackoverflow.com/questions/17579449/model-library-lazy-load-in-codeigniter
      function __get($name)
      {
         if (isset($this-&gt;$name) &amp;&amp; $this-&gt;$name instanceof CI_Model) 
          {
                return $this-&gt;$name;
          }
      }
    }
  </code></pre></li>
  </ol>
  
  <p>Once I can get this to work without errors; I will add my custom logic to load the right model or library.</p>
  
  <p>I want to do this WITHOUT modifying core.</p>