I'm battling with PHP Class inheritance and scope issues. Basically I have a baseclass with a bunch of useful methods (create, save, load) which the devs currently pass a table_name to . I would like to create a bunch of model classes which are empty but extend & inherit the baseclass and can have methods of the same name that get called instead of the baseclass version.
The code below im struggling to get the table_name in a static method from the model class, any advice?
class Model_Baseclass {
private $table_name;
public static function create($fields) {
$table_name = //self::table_name - parent::table_name - const $table_name
if ($table_name == NULL) {
throw new exception('You must specify a table.');
}
}
}
class Model_Content_Gallery extends Model_Baseclass {
public $table_name = 'Content_Gallery';
}
$old = Model_Baseclass::create(array('table_name' => 'Content_Gallery'));
$new = Model_Content_Gallery::create(array());
self::
, you're trying to call a static property. Yourprivate $table_name;
is not a static property, it's an instance property.private static $table_name;
would at least fix that, although I don't think that's all you have wrong. – Jared Farrish Dec 11 '11 at 18:55