protected abstract static function ... E_STRICT

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

 



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

-- 
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