PHP中的方法签名必须还是应该? [英] Is method signature in PHP a MUST or SHOULD?

查看:114
本文介绍了PHP中的方法签名必须还是应该?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是,如果用不是sfWebRequest实例的$request调用它,将是致命的还是警告?

I mean if it's called with $request which is not instance of sfWebRequest ,will it be fatal,or just a warning?

class jobActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->jobeet_job_list = Doctrine::getTable('JobeetJob')
      ->createQuery('a')
      ->execute();
  }

  // ...
}

推荐答案

这将是可捕获的致命错误.

It will be a catchable fatal error.

这里是一个例子:

class MyObj {}

function act(MyObj $o)
{
    echo "ok\n";
}

function handle_errors($errno, $str, $file, $line, $context)
{
    echo "Caught error " . $errno . "\n";
}

set_error_handler('handle_errors');

act(new stdClass());
/* Prints                                                                       
 *                                                                              
 * Caught error 4096                                                            
 * ok                                                                           
 */

如果没有set_error_handler调用,则代码将失败并显示错误:

If there wasn't a set_error_handler call the code will fail with an error:

Catchable fatal error: Argument 1 passed to act() must be an instance of MyObj, 
instance of stdClass given, called in /home/test/t.php on line 16 and defined in
/home/test/t.php on line 4

这篇关于PHP中的方法签名必须还是应该?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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