protected abstract static function ... E_STRICT
| From: | Johannes Ott | Date: | Wed, 11 Mar 2015 22:31:36 +0000 |
| Subject: | protected abstract static function ... E_STRICT | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-324622@lists.php.net to get a copy of this message | ||
Hi,
why PHP in Strict mode fires as warning for the declaration of a
abstract function:
What I want to do is:
abstract class Scalar {
protected $value;
public function __construct($value) {
if (static::valid($value)) {
$this->value = $value;
} else {
throw new RuntimeException();
}
}
/** each child has to have it's own function */
protected abstract static function valid($value);
}
final class Integer extends Scalar {
protected static function valid($value) {
return is_int($value);
}
}
final class Float extends Scalar {
protected static function valid($value) {
return is_float($value) || is_int($value);
}
}
The abstract superclass has no need implement the valid function but the
childclasses have to.
What I'm having as workaround at the moment:
abstract class Scalar {
...
protected static function valid($value) {
throw new BadMethodCallException('Method should be only called
in subclass');
}
}
Any better solutions for this?
Thanks,
--
DerOetzi