Wildbug Posted June 5, 2009 Share Posted June 5, 2009 I find it bizarre that PHP behaves the way it does regarding method definition context and static class variables ($this vs. self). The self keyword is almost useless; if it's only ever going to refer to the class in which it was defined, why wouldn't I just use the class name explicitly? /rant How can I have a value common to an extended class be correctly referenced in an inherited method? An example case: <?php abstract class Base { static protected $table_name = "none"; public function getTableName() { return self::$table_name; } } class ChildClass extends Base { static protected $table_name = "my_table"; } $cc = new ChildClass; echo $cc->getTableName(); // outputs "none" ?> I guess I could define an abstract method in the base class that should return the tablename. What's the standard practice for this situation in PHP? Link to comment https://forums.phpfreaks.com/topic/161070-how-to-static-variables-in-inherited-methods-for-php-530/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.