PHP 严格标准:这段代码有什么问题?
我在 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]);
}
}
并收到以下错误:
严格标准:静态函数 Geometry::fromArray() 不应该是抽象的
- 这种方法有什么问题吗?
- 有没有可行的替代方案来强制具体类实现此工厂方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否将 Geometry 设为一个接口,然后让 Point 实现它?
Could you make Geometry an interface, and have Point implement it?