PHP OOP: How can I access static field and object? -


i want call getallpersons() in class, receive error:

fatal error: cannot redeclare non static core\model::$db static models\person::$db

class person extends model {     protected static $db;     protected static $table = 'person';       function __construct() {         parent::__construct ();         self::$db = database::get ();     }       public static function getallpersons() {         return self::$db->select ( "select personid, firstname, lastname " . prefix . self::$table );         // $db->select not static     } } 

another.php:

$data ['persons'] = person::getpersons (); 

the problem self::$db (for example in getallpersons function) refers $db declared @ person class (which not defined). try following in code (change self:: static::):

function __construct() {         parent::__construct ();         static::$db = database::get ();      } 

the previous allow constructor initialize $db var once initialize object of class.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -