I just installed woocommerce 2.0 (on WordPress) on PHP 5.4, and I got this:
Strict Standards: Declaration of WC_Gateway_BACS::process_payment()
should be compatible with WC_Payment_Gateway::process_payment() in
D:mypathtohtdocswordpresspluginswoocommerceclassesgatewaysbacsclass-wc-gateway-bacs.php
on line…
I check the files and found that WC_Payment_Gateway
have no method process_payment()
.
I need to know how to resolve this (not by setting error_reporting()
).
What is Strict Standards in PHP exactly?
In what condition so we get that error?
WC_Payment_Gateway
is defined inabstract-wc-payment-gateway.php
and declares a methodwhile
WC_Gateway_BACS
defines it as(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
to
(*) keep in mind I know of woocommerce only since the last five minutes, so don’t take my word for it.
Quote from PHP Manual
You are receiving this error because WC_Gateway_BACS::process_payment() declaration is different than WC_Payment_Gateway::process_payment() (might be not the same amount of parameters etc). If WC_Payment_Gateway has no method process_payment, check it’s parent class 🙂
Also, if you want to disable STRICT errors, add ^ E_STRICT to your error reporting configuration, for example:
if you wanna keep OOP form without turning any error off, you can also:
When you are using the same function in a parent class and a child class, but the child class needs parameters while the parent one not, you’ll get the
Strict Standards
error.Example
Manager:
MenuManager extends Manager:
This example will generate an error:
Because we don’t have the same arguments to the function, so let’s trick this and add arguments, even though we’re not using them!
Manager:
MenuManager extends Manager:
Only one to be careful is that when using
getAtPosition()
fromMenuManager.class.php
, be sure you are actually sending 2 parameters, as we have to declare$parent = 0
in order to match the parent’s declaration.Every class extending
Manager
and not containinggetAtPosition()
will use the method fromManager
.If declared in a child class, php will use the method from the child class instead of the parent’s one. There is no
overloading
in PHP, so that is how I worked around it until it is properly implemented.Here is a better answer – https://stackoverflow.com/a/9243127/2165415
for example,
parentClass::customMethod($thing = false)
andchildClass::customMethod($thing)
so, when you call
customMethod()
for the class, it may trigger the error, because the child’s method hasn’t defined a default value for the first argument.