Updating inherited attributes without __construct()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a class that has a list of valid keys, and an array of values. When a value is added to the array it's key is first checked against the list of valid keys (this is to prevent injection issues we have been having later on in the project).

  class parent{
    private $validkeys = 'title,color,name';
    private $values = array();
  }
That class is inherited by other classes that mostly just have an expanded list of valid keys. I would like to be able to update the valid key list without having to craft a constructor for child objects. I would rather not give each child class the constructor,

  __construct()
  {
    $this->validkeys.= ',setting,...';
    parent::__construct();
  }

since most child classes have no need of a unique constructor.

I thought of defining a protected extended valid keys variable in the parent that the child could set that the parent constructor would combine with the valid keys.

class parent{
  private $validkeys = 'title,color,name';
  private $values = array();
  protected $extendedkeys;
  __construct(){
    $this->validkeys .= $this->extendedkeys;
  }
}

But the children may become parents for further child classes. And if the sub-child classes use the $extendedkeys variable it will overwrite the intermediate class's version.

Is there any way to tack on extra additional data by the child classes without creating a constructor. I am not wedded to strings as a means, it just needs to be able to hold a string value.

Thanks

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux