php - in_array() expects parameter 2 to be array, boolean given in line 45
Get the solution ↓↓↓In the error log of my server iВґm getting the following PHP Warning:
in_array() expects parameter 2 to be array, boolean given in " //..." on line 45.
In line 45 i have set a function that checks wether WooCommerce plug-in is active.
/**
* Construction function
*/
public function __construct() {
// Check if Woocomerce plugin is actived
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
return;
}
$this->new_duration = sober_get_option( 'product_newness' );
$this->parse_query();
$this->hooks();
}
Checking if itВґs active with the if statement is necessary, is there anything iВґm not seeing?
The error keeps popping up in my error log.
Answer
Solution:
You need to change the method how you verify if a plugin is available.
if(!is_plugin_active('woocommerce/woocommerce.php')) {
return;
}
Your method fails, because you check within_array()
which needs to have the 2nd parameter being an array, butapply_filters()
returns a bool.
Update
You could try to cast the result ofapply_filters()
being an array.
if ( ! in_array( 'woocommerce/woocommerce.php', (array)apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
return;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: fastcgi sent in stderr: "primary script unknown" while reading response header from upstream
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.