Php 有没有办法停止另一个方法的对象方法执行?
情况如下: 有一个单独的对象负责生成页面内容,我们可以称之为内容。另一个对象是它的“父-核心”对象。 Content对象调用Core方法*检查参数计数($parameters\u count)*,因此Core必须检查URI中给定的参数计数是否等于执行此方法时给定的整数($parameters\u count),如果不是-Core应生成错误页面并停止执行内容的呈现方法 有没有什么方法可以不使用if语句来实现这一点?只需在content类中使用*$core->Check_parameters_count(2)*,以简化特定渲染引擎程序员的工作 所有内容都应类似于此:Php 有没有办法停止另一个方法的对象方法执行?,php,oop,halt,Php,Oop,Halt,情况如下: 有一个单独的对象负责生成页面内容,我们可以称之为内容。另一个对象是它的“父-核心”对象。 Content对象调用Core方法*检查参数计数($parameters\u count)*,因此Core必须检查URI中给定的参数计数是否等于执行此方法时给定的整数($parameters\u count),如果不是-Core应生成错误页面并停止执行内容的呈现方法 有没有什么方法可以不使用if语句来实现这一点?只需在content类中使用*$core->Check_parameters_cou
class Core {
public function Check_parameters_count($parameters_count) {
if (count($this->parameters) != $parameters_count) {
$this->Show_error(404);
$this->Stop_executing($content, 'Render');
//or
stop($content->Render);
//or something similar..
}
}
}
class Content {
public function Render() {
//check given parameters so we could know which page should be rendered and how many parameters should be given
//...
//lets say we should have exactly 2 parameters
$parameters_count = 2;
//check it
$core->Check_parameters_count($parameters_count);
//if parameters count matched - continue method execution
//...
}
}
掷骰子
您有3个作用域:
- 函数A(函数B的调用方)
- 功能B
- 函数A的调用方