Ok, so I read a lot of posts about this here, but I think this is a specific and new question.
I want the functionality of what many of us here incorrectly call the "abstract static method". That is: I want a class that insists on classes that extend it to implement certain static methods .
There seem to be two ways around the issue under discussion, which does not allow abstract static, but both seem inelegant.
Problem
The following error is generated: "Strict PHP standards: the static function A :: fn () should not be abstract."
<?php
abstract class A
{
abstract static public function fn();
}
class B extends A
{
static public function fn()
{
}
}
Solution 1: use interfaces
<?php
interface iA {
static function fn();
}
abstract class A implements iA
{
}
class B extends A
{
static public function fn()
{
}
}
, (), . , , , ; , A .
, , "".
2:
abstract class A
{
static public function fn()
{
throw new Exception(get_called_class() . " must implement fn()");
}
}
class B extends A
{
static public function fn()
{
}
}
, fn() . . , .
- , ? , , , .