Question

Possible Duplicate:
Why does PHP 5.2+ disallow abstract static class methods?
Why can't you call abstract functions from abstract classes in PHP?

I'm running this code on PHP 5.3.8:

abstract class Geometry
{
    abstract public static function fromArray(array $array);
}

class Point extends Geometry
{
    public static function fromArray(array $point)
    {
        return new self($point[0], $point[1]);
    }
}

And receive the following error:

Strict Standards: Static function Geometry::fromArray() should not be abstract

  • What's wrong with this approach?
  • Any viable alternative to force concrete classes to implement this factory method?
Was it helpful?

Solution

Could you make Geometry an interface, and have Point implement it?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top