PHP多个接口冲突,没有报错
我对此代码的结果感到困惑:
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
interface interface1 {
public function myMethod1(string $param1, int $param2);
public function myMethod2(int $param1);
}
interface interface2 {
public function myMethod1(int $param1, string $param2, float $param3);
public function myMethod2(float $param1);
}
class SomeClass implements interface1, interface2 {
public function myMethod1(array $param1) {
echo "In method2";
var_dump($param1);
}
public function myMethod2( array $param1, array $param2, array $param3) {
echo "In Method2";
var_dump($param1);
}
}
$c = new SomeClass();
$c->myMethod1();
$c->myMethod2();
exit;
关于参数类型和参数数量,多个接口与参数相冲突。并且代码在没有任何必需参数的情况下调用方法。对于实现接口的类中的每个方法,方法签名都是错误的。
该代码在没有报告的错误或警告的情况下运行,并且不会产生输出,但是发出255的代码。在调试时,它不会在任何断点上停止。至少不应该抛出一个错误或警告消息吗?
I'm baffled by the results of this code:
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
interface interface1 {
public function myMethod1(string $param1, int $param2);
public function myMethod2(int $param1);
}
interface interface2 {
public function myMethod1(int $param1, string $param2, float $param3);
public function myMethod2(float $param1);
}
class SomeClass implements interface1, interface2 {
public function myMethod1(array $param1) {
echo "In method2";
var_dump($param1);
}
public function myMethod2( array $param1, array $param2, array $param3) {
echo "In Method2";
var_dump($param1);
}
}
$c = new SomeClass();
$c->myMethod1();
$c->myMethod2();
exit;
The multiple interfaces are in conflict with regard to argument types and number of arguments. And the code calls the methods without any of the required arguments. The method signature is wrong for every method in the class that implements the interfaces.
The code runs with no reported errors or warnings and produces no output, but issues a code of 255. When debugging, it doesn't stop at any breakpoints. Shouldn't at least one error or warning message be thrown?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
飞行员错误。多亏了Sammitch和Barmar的评论,该谜团得到了解决。首先,将“ e_all”放在引号中抑制了错误。当我解决这个问题时,我想确保e_strict启动,所以,就像一个白痴一样,我将其更改为e_all&amp; e_strict,也抑制了错误,直到我将其更改为e_all | e_strict(e_all本身就是这样做的)。感谢您的帮助。
Pilot Error. Thanks to Sammitch's and Barmar's comments, the mystery is solved. First, putting 'E_ALL' in quotes suppressed the error. When I fixed that, I wanted to make sure E_STRICT was on, so, like an idiot, I changed it to E_ALL & E_STRICT, which also suppressed the error, until I changed it to E_ALL | E_STRICT (E_ALL by itself would have done it). Thanks for the help.