Welcome Guest, Not a member yet? Register   Sign In
Can you have too many static functions?
#1

(This post was last modified: 06-27-2015, 01:16 AM by jLinux.)

Ive been working with CI a lot recently, and I setup my models so the methods could be used in a static context... Example below:
Code:
<?php

class Accounts_model extends CI_Model
{
   private static $db;

   public function __construct()
   {
       parent::__construct();

       $CI =& get_instance();

       self::$db = $CI->db;

   }

   public static function get_id_from_username($username = NULL)
   {
       self::$db->select('Accounts.account_id')
                ->where('Accounts.username', $username)
                ->from('Accounts');

       $query = self::$db->get();

       return $query->result();
   }
}

And with that kinda setup... since when you load a model in CI, the class is only loaded once, I can create every method as static...

My question, is can you have TOO MANY static methods? is it bad practice? LMK whatcha think. I mean it works fine, since I dont load the classes more than once.. so idk
Reply


Messages In This Thread
Can you have too many static functions? - by jLinux - 06-27-2015, 12:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB