Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Class __int call twice
  • Hi All, I've folow the classes doc (http://docs.fuelphp.com/general/classes.html) and add a simple echo "hello world" into the __int() function (nasty but good way to test) of my classes/base.php file. It seem the method is call twice because I have 2 "hello word" print on top of my page. Is it normal ??? thanks :)
  • ok, I get it! I used to call Base::_init(); from my controller, so base.php was 1/ call (implicit call _init() method), 2/ perform _init() a second time. I added a test() method and call it from the controller instead of _int() :
    class Base
    {
     private static $i = 0;
     
     public static function _init()
     {
      ++self::$i;
      }
     
     public static function test()
     {
      ++self::$i;
      echo 'hi all from test!: '.self::$i;
     }
    }
    

    and it print "hi all from test!: 2", great! :)
  • _init() is called as soon as the class is loaded. See it as a static equivalent of __construct(). There is no need to call it yourself.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion