It returns null
since the $table_name
is not assigned , Instead you should add return static::$table_name;
inside the getName()
of the ModelMain
class to enable the Late Static Binding
, so it does displaypost
as 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 to introduce LSB
}
}
class Post extends \Model\ModelMain {
public static $table_name = "post";
}
echo Post::getName();