3

I am working on a website using word press and it is my first time to encounter this problem after I updated my word press version and all the plugins and the database,this is what I encountered.

This is the error

Fatal error: Can't use function return value in write context in ****.com\httpdocs\wp-content\plugins\popup-builder\popup-builder.php on line 335

Line 335

if(!empty(get_option("SG_ALL_POSTS")) && is_array(get_option("SG_ALL_POSTS")) && !(is_page() || is_home()  || is_front_page())) {
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Teapetetose
  • 35
  • 1
  • 5

2 Answers2

1

You need to upgrade PHP to version 5.5 or newer.

This is basically a duplicate of Can't use method return value in write context but since this isn't your code I'm not going to mark it as a dupe. It's not a matter of editing code to fix the error, it's a matter of setting up your server environment so the code runs without issues.

The root of the problem is that empty() isn't a true function in PHP. It's a feature built into the language. empty() wants a variable passed to it, and the normal variable passing rules don't apply. Normally you could pass the result of a function call and PHP would create a temporary variable but empty() can only see real variables.

PHP 5.5 changed that so empty() works with temporary variables, too.

Community
  • 1
  • 1
Dave Ross
  • 3,313
  • 1
  • 24
  • 21
0

this is the function code

function sgOnloadPopup()
{
    $page = get_queried_object_id();
    $popup = "sg_promotional_popup";
    /* If popup is set on page load */
    $popupId = SGPopup::getPagePopupId($page, $popup);
    /* get all popups id which set in current page by class */
    $popupsIdByClass = getPopupIdInPageByClass($page);

    if(POPUP_BUILDER_PKG > POPUP_BUILDER_PKG_FREE){
        delete_option("SG_MULTIPLE_POPUP");

        /* Retrun all popups id width selected On All Pages */
        $popupsId = SgPopupPro::allowPopupInAllPages($page);

        $data = get_option("SG_ALL_POSTS");
        if(!empty($data) && is_array($data) && !(is_page() || is_home()  || is_front_page())) {
        /*if(!empty(get_option("SG_ALL_POSTS")) && is_array(get_option("SG_ALL_POSTS")) && !(is_page() || is_home()  || is_front_page())) {*/
            /* Add to popups Queue */
            $popupsId = array_merge(get_option("SG_ALL_POSTS"), $popupsId);
        }
        if(!empty(get_option("SG_ALL_PAGES")) && is_array(get_option("SG_ALL_PAGES")) && (is_page() || is_home()  || is_front_page())) {
            /* Add to popups Queue */
            $popupsId = array_merge(get_option("SG_ALL_PAGES"), $popupsId);
        }

        /* $popupsId[0] its last selected popup id */
        if(isset($popupsId[0])) {
            delete_option("SG_MULTIPLE_POPUP");
            if(count($popupsId) > 0) {
                update_option("SG_MULTIPLE_POPUP",$popupsId);
            }
            foreach ($popupsId as $queuePupupId) {

                showPopupInPage($queuePupupId);
            }

            $popupsId = json_encode($popupsId);
        }
        else {
            $popupsId = json_encode(array());
        }
        echo '<script type="text/javascript">
            SG_POPUPS_QUEUE = '.$popupsId.'</script>';
    }

    //If popup is set for all pages
    if($popupId != 0) {
        showPopupInPage($popupId);
    }

    if(!empty($popupsIdByClass)) {
        foreach ($popupsIdByClass as $popupId) {
            sgRenderPopupScript($popupId);
        }
    }
    return false;
}
Teapetetose
  • 35
  • 1
  • 5