oop - Are abstract members possible in PHP? -


i'd develop abstract class extended fit custom requirements. of methods implemented in base class. however, rely heavily on values set in members, child class should define. reason i'm saying "abstract" class want force extenders of class define values members. possible?

i know can define methods abstract , force extenders implement those. i'm not sure members. furthermore, design practice?

example:

abstract class foo_bar {     // want child class define these     private $member1 = 0;     private $member2 = 0;     private $member3 = 0;      // child class , instances can access     public function foo()     {         return 'foo';     }      // child class must implement     abstract function bar(); } 

in short: no. there's no such thing abstract properties in php.

you may declare properties protected in abstract class child inherits them. if you'd declare them abstract, there's no guarantee child implements them with useful values, has same effect.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -