php - Overwrite static variable in fuelphp -


i have sample code in php

class first {     public static $name;         public static function getname() {        return static::$name;     } }  class second extends first {     public static $name = 'second'; }  echo second::getname();  // print 'second' 

but when write fuelphp:

file 1:

namespace model; use \db;  class modelmain extends \model {     public static $table_name;      public static function getname() {         return self::$table_name;     } } 

file 2

class post extends \model\modelmain {     public static $table_name = "post"; } 

when call

post::getname() // print null 

i expected print post. wrong it?

it returns null since $table_name not assigned , instead should add return static::$table_name; inside getname() of modelmain class enable late static binding , displaypost output.

late static binding...

<?php  namespace model; use \db;  class modelmain extends \model  {     public static $table_name;      public static function getname() {         return static::$table_name; //<--- add static here introduce lsb     } }   class post extends \model\modelmain {     public static $table_name = "post"; }   echo post::getname(); 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -