reduxframework / redux-framework-4

Redux v4
https://redux.io/redux-4/
Other
96 stars 32 forks source link

Error Can't use function return value in write while activating Redux #200

Closed mohammedeisa closed 3 years ago

mohammedeisa commented 3 years ago

Issue description:

A client complained that he got the following error while activating Redux:

Fatal error: Can't use function return value in write context in /home1/landmark/public_html/wp-content/plugins/redux-framework/redux-core/inc/classes/class-redux-functions-ex.php on line 196

Steps to reproduce"

I'm not able to reproduce the issue but the code shows that there is an issue that can be fixed even without the need to replicate the issue.

The current code:

Here is the function: public static function s() { if ( ! empty( get_option( 'redux_p' . 'ro_lic' . 'ense_key', false ) ) ) { // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found $s = get_option( 'redux_p' . 'ro_l' . 'icense_status', false ); // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found if ( ! empty( $s ) && in_array( $s, array( 'valid', 'site_inactive' ), true ) ) { return true; } } return false; }

Proposed solution:

Split line 196 into two lines to be like the following:

public static function s() { $redux_pro_license_key= get_option( 'redux_p' . 'ro_lic' . 'ense_key', false ) ; if ( ! empty($redux_pro_license_key) ) { // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found $s = get_option( 'redux_p' . 'ro_l' . 'icense_status', false ); // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found if ( ! empty( $s ) && in_array( $s, array( 'valid', 'site_inactive' ), true ) ) { return true; } } return false; }

kprovance commented 3 years ago

PHP empty() isn't the best thing ever invented. It's been known to cause the aforementioned error (see: https://stackoverflow.com/questions/17139264/cant-use-function-return-value-in-write-context). Personally, I avoid it in lieu of more reliable concepts, especially where the return is mixed.

Try:


public static function s() { 
    if ( ! get_option( 'redux_p' . 'ro_lic' . 'ense_key', false ) ) { // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found
        $s = get_option( 'redux_p' . 'ro_l' . 'icense_status', false ); // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found

        if ( false !== $s && in_array( $s, array( 'valid', 'site_inactive' ), true ) ) {
            return true;
        }
    }

    return false; 
}
`