Say I have the following:
<?php
abstract class MyParent
{
public static $table_name;
public static get_all(){
return query("SELECT * FROM {$this->table_name}");
}
public static get_all2(){
return query("SELECT * FROM ".self::table_name);
}
}
class Child extends MyParent
{ public static $table_name = 'child'; }
?>
Assuming that it is querycorrectly defined, none of these methods does what I want: get_all () throws Fatal error: Using $this when not in object context in /path/to/foo.php on line xx, because it $thisis an instance variable.
and get_all2 () throws Fatal error: Undefined class constant 'table_name' in /path/to/foo.php on line xxbecause it is selfstatically determined.
It seems that such a thing is a whole inheritance, so it should be possible, at least easily, if not elegantly. (This is still PHP)
What should I do?
source
share