Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notice on single entry page for include/functions_config.inc.php #860

Open
bauigel opened this issue Jan 19, 2025 · 2 comments
Open

notice on single entry page for include/functions_config.inc.php #860

bauigel opened this issue Jan 19, 2025 · 2 comments

Comments

@bauigel
Copy link

bauigel commented Jan 19, 2025

Notice: Only variables should be assigned by reference in ./include/functions_config.inc.php on line 1426.

From ChatGPT

The error occurs because PHP no longer allows assigning a reference (&) directly to the return value of a function. The specific problematic line is:

$_groups =& serendipity_db_query(...);
This is not valid in modern PHP versions because a function's return value is not considered a variable that can hold a reference.

ChatGPT want to change the function like this:

function &serendipity_getGroups($authorid, $sequence = false) {
    global $serendipity;

    // Funktionsrückgabewert in eine normale Variable speichern
    $_groups = serendipity_db_query(
        "SELECT g.id  AS confkey,
                g.name AS confvalue,
                g.id   AS id,
                g.name AS name
         FROM {$serendipity['dbPrefix']}authorgroups AS ag
              LEFT OUTER JOIN {$serendipity['dbPrefix']}groups AS g
              ON g.id = ag.groupid
         WHERE ag.authorid = " . (int)$authorid,
        false,
        'assoc'
    );

    if (!is_array($_groups)) {
        $groups = array();
    } else {
        // Referenz auf das Array setzen
        $groups = $_groups;
    }

    if ($sequence) {
        $rgroups = array();
        foreach ($groups as $grouprow) {
            $rgroups[] = $grouprow['confkey'];
        }
    } else {
        // Referenz auf Gruppen setzen
        $rgroups = $groups;
    }

    return $rgroups;
}

Didn't try it until now. Any recommendations?

@garvinhicking
Copy link
Member

This is basically a performance optimization to prevent "cloning" array structures.

We should probably be able to just replace "=&" with "=" whenever we assign a serendipity_xxx function return value, specifically the db_* functions.

@bauigel
Copy link
Author

bauigel commented Jan 19, 2025

Another =& is on line 1120. Got a notice when I opened the static pages overview in backend.

1116 function &serendipity_getPermissions($authorid) {
1117     global $serendipity;
1118 
1119         // Get group information
1120         $groups =& serendipity_db_query("SELECT ag.groupid, g.name, gc.property, gc.value                                                                                                               
1121                                           FROM {$serendipity['dbPrefix']}authorgroups AS ag
1122                                LEFT OUTER JOIN {$serendipity['dbPrefix']}groups AS g
1123                                             ON ag.groupid = g.id
1124                                LEFT OUTER JOIN {$serendipity['dbPrefix']}groupconfig AS gc
1125                                             ON gc.id = g.id
1126                                          WHERE ag.authorid = " . (int)$authorid);
1127         $perm = array('membership' => array());
1128         if (is_array($groups)) {
1129             foreach($groups AS $group) {
1130                 $perm['membership'][$group['groupid']]       = $group['groupid'];
1131                 $perm[$group['groupid']][$group['property']] = $group['value'];
1132             }
1133         }
1134         return $perm;
1135 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants