严格的标准:''应该与...兼容'的声明

egi*_*gig 19 php wordpress woocommerce

我刚刚在PHP 5.4上安装了woocommerce 2.0(在Wordpress上),我得到了这个:

严格标准:WC_Gateway_BACS :: process_payment()的声明应与D:\ my\path\to\htdocs\wordpress\plugins\woocommerce\classes\gateways\bacs\class-wc-gateway中的WC_Payment_Gateway :: process_payment()兼容-bacs.php在线......

我检查文件,发现WC_Payment_Gateway没有方法process_payment().我需要知道如何解决这个问题(不是通过设置error_reporting()).

什么是PHP中的严格标准
在什么条件下我们得到那个错误?

Vol*_*erK 19

WC_Payment_Gateway is defined in abstract-wc-payment-gateway.php and declares a method

function process_payment() {}
Run Code Online (Sandbox Code Playgroud)

while WC_Gateway_BACS defines it as

function process_payment( $order_id ) { ...
Run Code Online (Sandbox Code Playgroud)

(maybe you mixed up WC_Payment_Gateway and WC_Payment_Gateways).

So, different signature (0 parameters vs 1 parameter) -> strict error.
Since it seems*to be used always with one parameter you could change

function process_payment() {}
Run Code Online (Sandbox Code Playgroud)

to

function process_payment($order_id) {}
Run Code Online (Sandbox Code Playgroud)

(*) keep in mind I know of woocommerce only since the last five minutes, so don't take my word for it.


小智 12

从PHP手册引用

在PHP 5中,可以使用新的错误级别E_STRICT.在PHP 5.4.0之前,E_STRICT未包含在E_ALL中,因此您必须在> PHP <5.4.0中明确启用此类错误级别.在开发期间启用E_STRICT有一些好处.STRICT消息>提供有助于确保代码的最佳互操作性和转发>兼容性的建议.这些消息可能包括静态调用非静态>方法,在"使用的特征"中定义的兼容类定义中定义属性,以及PHP 5.3之前的某些不推荐使用的特性会发出E_STRICT错误,例如通过引用分配对象实例.

您收到此错误是因为WC_Gateway_BACS :: process_payment()声明与WC_Payment_Gateway :: process_payment()不同(可能不是相同数量的参数等).如果WC_Payment_Gateway没有方法process_payment,请检查它的父类:)

此外,如果要禁用STRICT错误,请将^ E_STRICT添加到错误报告配置中,例如:

error_reporting(E_ALL ^ E_STRICT);
Run Code Online (Sandbox Code Playgroud)


Saj*_*azy 8

如果您想保留OOP表格而不关闭任何错误,您还可以:

class A
{
    public function foo() {
        ;
    }
}
class B extends A
{
    /*instead of : 
    public function foo($a, $b, $c) {*/
    public function foo() {
        list($a, $b, $c) = func_get_args();
        // ...

    }
}
Run Code Online (Sandbox Code Playgroud)

  • 丑陋,但有时需要. (9认同)