在PHP中抛出NotImplementedError? [英] Throw a NotImplementedError in PHP?

查看:120
本文介绍了在PHP中抛出NotImplementedError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中有一种NotImplementedError吗?



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

解决方案

PHP没有内置的 NotImplementedException 然而欢迎您创建自己的。我认为 BadMethodCallException 将关闭成为扩展的体面候选人

 类NotImplementedException扩展BadMethodCallException 
{}

...并在您的方法中

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

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

 抛出新异常('未实现'); 


Is there a kind of NotImplementedError in PHP?

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 does not have a built-in NotImplementedException however you're welcome to create your own. I suppose BadMethodCallException comes close which would be a decent candidate for extension

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');

这篇关于在PHP中抛出NotImplementedError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆