在 PHP 中抛出 NotImplementedError?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8092886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:57:16  来源:igfitidea点击:

Throw a NotImplementedError in PHP?

phpexception

提问by berkes

Is there a kind of NotImplementedError in PHP?

PHP 中有一种 NotImplementedError 吗?

I want to add these to some stub-methods and interfaces, so as to warn classes that extend me, they still have work to do. Or is this achieved differently in PHP?

我想将这些添加到一些存根方法和接口中,以警告扩展我的类,他们还有工作要做。或者这是在 PHP 中实现的不同?

回答by Phil

PHP does not have a built-in NotImplementedExceptionhowever you're welcome to create your own. I suppose BadMethodCallExceptioncomes close which would be a decent candidate for extension

PHP 没有内置,NotImplementedException但欢迎您创建自己的。我想很BadMethodCallException接近这将是一个不错的延期候选人

class NotImplementedException extends BadMethodCallException
{}

... and in your method

......在你的方法中

public function notImplementedMethod()
{
    throw new NotImplementedException();
}

You can also very simply do something like this

你也可以非常简单地做这样的事情

throw new Exception('Not implemented');