I would like to prevent a child class from redeclaring some parent's attributes. How can I do that?
EDIT: If my parent class has a "title" property, i don't want that children can (re)declare property with this name
I would like to prevent a child class from redeclaring some parent's attributes. How can I do that?
EDIT: If my parent class has a "title" property, i don't want that children can (re)declare property with this name
i'm not sure if this will work but you could try playing with the Reflection class and detect if any child has redeclared the property and then fire an exception or something
UPDATE:
check this links out:
http://www.php.net/manual/en/reflectionproperty.getdeclaringclass.php
and
http://www.php.net/manual/en/reflectionproperty.setaccessible.php
It should help
Define class variable as private.
private $_var = 'would not be changed by a child class';
private $_var = 'would not be changed by a child class, or even usable in child class';
Commented
Apr 8, 2012 at 23:44
const INVARIABLE
and const INVARIABLE = parent::INVARIABLE
. Still, you make a valid point saying it's the programmers responsibility to know what (s)he's doing, and to document the code
Commented
May 11, 2012 at 9:23