CodeIgniter Forums
create my own library with php 4 and get_instance - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: create my own library with php 4 and get_instance (/showthread.php?tid=3491)



create my own library with php 4 and get_instance - El Forum - 10-05-2007

[eluser]ariok[/eluser]
Hi all!
I read up on creating library in user documentation
and about the get_instance() function i founded this :

Quote:Also, please note: If you are running PHP 4 it's usually best to avoid calling get_instance() from within your class constructors. PHP 4 has trouble referencing the CI super object within application constructors since objects do not exist until the class is fully instantiated.

so.. if i need to use helper in my library what i have to do?? where i have to define the CI object reference ??

Thank you for your help


create my own library with php 4 and get_instance - El Forum - 10-05-2007

[eluser]Armchair Samurai[/eluser]
Call get_instance() from your functions when you need it:
Code:
class Foo {

   function Foo()
   {
      /* get_instance() not here */
   }

   function bar()
   {
      $ci =& get_instance();

      $ci->load->helper('helpername');
   }

}