Skip to content

Commit f425f7f

Browse files
authored
Remove & reference declaration from db_query to avoid warning (#870)
* Remove & reference declaration from db_query to avoid warning Also adjusts the code that calls the function with a prepended &, as that would have caused a new warning. Fixes #848 * Fix reference return warning for getFile Is also not returning a sharable variable * document change
1 parent a42183c commit f425f7f

12 files changed

+36
-34
lines changed

docs/NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Version 2.6-alpha1 ()
22
------------------------------------------------------------------------
3+
* Avoid PHP 8 warning about incurrect reference return of db_query
4+
function
35

46
* PHP 8.4 fix: Remove deprecated constant E_STRICT
57

include/db/mysqli.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function serendipity_db_in_sql($col, &$search_ids, $type = ' OR ') {
5858
* @param boolean If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignored on DUPLICATE INDEX queries and the likes)
5959
* @return mixed Returns the result of the SQL query, depending on the input parameters
6060
*/
61-
function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
61+
function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
6262
global $serendipity;
6363
$type_map = array('assoc' => MYSQLI_ASSOC, 'num' => MYSQLI_NUM, 'both' => MYSQLI_BOTH, 'true' => true, 'false' => false);
6464

include/db/pdo-postgres.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function serendipity_db_insert_id($table = '', $id = '') {
199199
* @param boolean If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignroed on DUPLICATE INDEX queries and the likes)
200200
* @return mixed Returns the result of the SQL query, depending on the input parameters
201201
*/
202-
function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
202+
function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
203203
global $serendipity;
204204
$type_map = array(
205205
'assoc' => PDO::FETCH_ASSOC,

include/db/pdo-sqlite.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function serendipity_db_insert_id($table = '', $id = '') {
215215
* @param boolean If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignroed on DUPLICATE INDEX queries and the likes)
216216
* @return mixed Returns the result of the SQL query, depending on the input parameters
217217
*/
218-
function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
218+
function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
219219
global $serendipity;
220220
$type_map = array(
221221
'assoc' => PDO::FETCH_ASSOC,

include/db/postgres.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function serendipity_db_insert_id($table = '', $id = '') {
203203
* @param boolean If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignroed on DUPLICATE INDEX queries and the likes)
204204
* @return mixed Returns the result of the SQL query, depending on the input parameters
205205
*/
206-
function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
206+
function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
207207
global $serendipity;
208208
$type_map = array(
209209
'assoc' => PGSQL_ASSOC,

include/db/sqlite.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function serendipity_db_in_sql($col, &$search_ids, $type = ' OR ') {
209209
* @param boolean If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignored on DUPLICATE INDEX queries and the likes)
210210
* @return mixed Returns the result of the SQL query, depending on the input parameters
211211
*/
212-
function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false)
212+
function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false)
213213
{
214214
global $serendipity;
215215
$type_map = array(

include/db/sqlite3.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function serendipity_db_in_sql($col, &$search_ids, $type = ' OR ') {
218218
* @param boolean If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignroed on DUPLICATE INDEX queries and the likes)
219219
* @return mixed Returns the result of the SQL query, depending on the input parameters
220220
*/
221-
function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false)
221+
function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false)
222222
{
223223
global $serendipity;
224224
$type_map = array(

include/db/sqlite3oo.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function serendipity_db_in_sql($col, &$search_ids, $type = ' OR ') {
224224
* @param boolean If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignroed on DUPLICATE INDEX queries and the likes)
225225
* @return mixed Returns the result of the SQL query, depending on the input parameters
226226
*/
227-
function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false)
227+
function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false)
228228
{
229229
global $serendipity;
230230
$type_map = array(

include/db/sqlrelay.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function generate_resultset($cursor, $result_type = 'sqlr_BOTH') {
113113
return $return_row;
114114
}
115115

116-
function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
116+
function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
117117
global $serendipity;
118118
$type_map = array(
119119
'assoc' => sqlr_ASSOC,

include/functions_config.inc.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@ function serendipity_load_configuration($author = null) {
305305

306306
if (!empty($author)) {
307307
// Replace default configuration directives with user-relevant data
308-
$rows =& serendipity_db_query("SELECT name,value
308+
$rows = serendipity_db_query("SELECT name,value
309309
FROM {$serendipity['dbPrefix']}config
310310
WHERE authorid = '". (int)$author ."'");
311311
} else {
312312
// Only get default variables, user-independent (frontend)
313-
$rows =& serendipity_db_query("SELECT name, value
313+
$rows = serendipity_db_query("SELECT name, value
314314
FROM {$serendipity['dbPrefix']}config
315315
WHERE authorid = 0");
316316
}
@@ -550,7 +550,7 @@ function serendipity_authenticate_author($username = '', $password = '', $is_has
550550
username = '" . serendipity_db_escape_string($username) . "'";
551551
if ($debug) fwrite($fp, date('Y-m-d H:i') . ' - Login check (' . serialize($is_hashed) . ', ' . $_SESSION['serendipityPassword'] . '):' . $query . "\n");
552552

553-
$rows =& serendipity_db_query($query, false, 'assoc');
553+
$rows = serendipity_db_query($query, false, 'assoc');
554554
if (is_array($rows)) {
555555
$is_valid_user = false;
556556
foreach($rows AS $row) {
@@ -1117,7 +1117,7 @@ function &serendipity_getPermissions($authorid) {
11171117
global $serendipity;
11181118

11191119
// Get group information
1120-
$groups =& serendipity_db_query("SELECT ag.groupid, g.name, gc.property, gc.value
1120+
$groups = serendipity_db_query("SELECT ag.groupid, g.name, gc.property, gc.value
11211121
FROM {$serendipity['dbPrefix']}authorgroups AS ag
11221122
LEFT OUTER JOIN {$serendipity['dbPrefix']}groups AS g
11231123
ON ag.groupid = g.id
@@ -1340,7 +1340,7 @@ function &serendipity_getAllGroups($apply_ACL_user = false) {
13401340
global $serendipity;
13411341

13421342
if ($apply_ACL_user) {
1343-
$groups =& serendipity_db_query("SELECT g.id AS confkey,
1343+
$groups = serendipity_db_query("SELECT g.id AS confkey,
13441344
g.name AS confvalue,
13451345
g.id AS id,
13461346
g.name AS name
@@ -1350,7 +1350,7 @@ function &serendipity_getAllGroups($apply_ACL_user = false) {
13501350
WHERE ag.authorid = " . (int)$apply_ACL_user . "
13511351
ORDER BY g.name", false, 'assoc');
13521352
} else {
1353-
$groups =& serendipity_db_query("SELECT g.id AS confkey,
1353+
$groups = serendipity_db_query("SELECT g.id AS confkey,
13541354
g.name AS confvalue,
13551355
g.id AS id,
13561356
g.name AS name
@@ -1378,7 +1378,7 @@ function &serendipity_fetchGroup($groupid) {
13781378
global $serendipity;
13791379

13801380
$conf = array();
1381-
$groups =& serendipity_db_query("SELECT g.id AS confkey,
1381+
$groups = serendipity_db_query("SELECT g.id AS confkey,
13821382
g.name AS confvalue,
13831383
g.id AS id,
13841384
g.name AS name,
@@ -1416,7 +1416,7 @@ function &serendipity_fetchGroup($groupid) {
14161416
function &serendipity_getGroups($authorid, $sequence = false) {
14171417
global $serendipity;
14181418

1419-
$_groups =& serendipity_db_query("SELECT g.id AS confkey,
1419+
$_groups = serendipity_db_query("SELECT g.id AS confkey,
14201420
g.name AS confvalue,
14211421
g.id AS id,
14221422
g.name AS name
@@ -1452,7 +1452,7 @@ function &serendipity_getGroups($authorid, $sequence = false) {
14521452
function &serendipity_getGroupUsers($groupid) {
14531453
global $serendipity;
14541454

1455-
$groups =& serendipity_db_query("SELECT g.name AS name,
1455+
$groups = serendipity_db_query("SELECT g.name AS name,
14561456
a.realname AS author,
14571457
a.authorid AS id
14581458
FROM {$serendipity['dbPrefix']}authorgroups AS ag
@@ -1523,7 +1523,7 @@ function serendipity_addGroup($name) {
15231523
function &serendipity_getDBPermissionNames() {
15241524
global $serendipity;
15251525

1526-
$config =& serendipity_db_query("SELECT property FROM {$serendipity['dbPrefix']}groupconfig GROUP BY property ORDER BY property", false, 'assoc');
1526+
$config = serendipity_db_query("SELECT property FROM {$serendipity['dbPrefix']}groupconfig GROUP BY property ORDER BY property", false, 'assoc');
15271527

15281528
return $config;
15291529
}
@@ -1809,7 +1809,7 @@ function serendipity_ACLGet($artifact_id, $artifact_type, $artifact_mode, $artif
18091809
AND artifact_id = '" . (int)$artifact_id . "'
18101810
AND artifact_mode = '" . serendipity_db_escape_string($artifact_mode) . "'
18111811
AND artifact_index = '" . serendipity_db_escape_string($artifact_index) . "'";
1812-
$rows =& serendipity_db_query($sql, false, 'assoc');
1812+
$rows = serendipity_db_query($sql, false, 'assoc');
18131813

18141814
if (!is_array($rows)) {
18151815
return false;
@@ -1870,7 +1870,7 @@ function serendipity_ACLCheck($authorid, $artifact_id, $artifact_type, $artifact
18701870
AND ( {$artifact_sql['where']} )
18711871
GROUP BY result";
18721872

1873-
$res =& serendipity_db_query($sql, true, 'assoc');
1873+
$res = serendipity_db_query($sql, true, 'assoc');
18741874
if (is_array($res) && !empty($res['result'])) {
18751875
return true;
18761876
}
@@ -2132,7 +2132,7 @@ function &serendipity_loadThemeOptions(&$template_config, $okey = '', $bc_bool =
21322132
$okey = $serendipity['template'];
21332133
}
21342134

2135-
$_template_vars =& serendipity_db_query("SELECT name, value FROM {$serendipity['dbPrefix']}options
2135+
$_template_vars = serendipity_db_query("SELECT name, value FROM {$serendipity['dbPrefix']}options
21362136
WHERE okey = 't_" . serendipity_db_escape_string($okey) . "'
21372137
OR okey = 't_global'", false, 'assoc', false, 'name', 'value');
21382138
if (!is_array($_template_vars)) {

include/functions_entries.inc.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function serendipity_deleteCategory($category_range, $admin_category) {
3636
function serendipity_fetchCategoryRange($categoryid) {
3737
global $serendipity;
3838

39-
$res =& serendipity_db_query("SELECT category_left, category_right, hide_sub FROM {$serendipity['dbPrefix']}category WHERE categoryid='". (int)$categoryid ."'");
39+
$res = serendipity_db_query("SELECT category_left, category_right, hide_sub FROM {$serendipity['dbPrefix']}category WHERE categoryid='". (int)$categoryid ."'");
4040
if (!is_array($res) || !isset($res[0]['category_left']) || !isset($res[0]['category_right'])) {
4141
$res = array(array('category_left' => 0, 'category_right' => 0));
4242
}
@@ -103,7 +103,7 @@ function serendipity_fetchCategoryInfo($categoryid, $categoryname = '') {
103103
FROM {$serendipity['dbPrefix']}category AS c
104104
WHERE category_name = '" . serendipity_db_escape_string($categoryname) . "'";
105105

106-
$ret =& serendipity_db_query($query);
106+
$ret = serendipity_db_query($query);
107107
return $ret[0];
108108
} else {
109109
$query = "SELECT
@@ -117,7 +117,7 @@ function serendipity_fetchCategoryInfo($categoryid, $categoryname = '') {
117117
FROM {$serendipity['dbPrefix']}category AS c
118118
WHERE categoryid = " . (int)$categoryid;
119119

120-
$ret =& serendipity_db_query($query);
120+
$ret = serendipity_db_query($query);
121121
return $ret[0];
122122
}
123123
}
@@ -145,7 +145,7 @@ function &serendipity_fetchEntryCategories($entryid) {
145145
WHERE ec.entryid = {$entryid}
146146
ORDER BY c.category_name ASC";
147147

148-
$cat =& serendipity_db_query($query,false,'assoc');
148+
$cat = serendipity_db_query($query,false,'assoc');
149149

150150
if (!is_array($cat)) {
151151
$arr = array();
@@ -487,7 +487,7 @@ function &serendipity_fetchEntries($range = null, $full = true, $limit = '', $fe
487487
return $query;
488488
}
489489

490-
$ret =& serendipity_db_query($query, $fetch_single, 'assoc');
490+
$ret = serendipity_db_query($query, $fetch_single, 'assoc');
491491

492492
if (is_string($ret)) {
493493
die("Query failed: $ret");
@@ -550,7 +550,7 @@ function serendipity_fetchEntryData(&$ret) {
550550
WHERE " . serendipity_db_in_sql('ec.entryid', $search_ids) . "
551551
ORDER BY c.category_name ASC";
552552

553-
$search_ret =& serendipity_db_query($query, false, 'assoc');
553+
$search_ret = serendipity_db_query($query, false, 'assoc');
554554

555555
if (is_array($search_ret)) {
556556
serendipity_plugin_api::hook_event('multilingual_strip_langs', $search_ret, array('category_name','category_description'));
@@ -630,7 +630,7 @@ function &serendipity_fetchEntry($key, $val, $full = true, $fetchDrafts = 'false
630630
{$cond['single_orderby']}
631631
LIMIT 1";
632632

633-
$ret =& serendipity_db_query($querystring, true, 'assoc');
633+
$ret = serendipity_db_query($querystring, true, 'assoc');
634634

635635
if (is_array($ret)) {
636636
$ret['categories'] =& serendipity_fetchEntryCategories($ret['id']);
@@ -657,7 +657,7 @@ function &serendipity_fetchEntryProperties($id) {
657657
$parts = array();
658658
serendipity_plugin_api::hook_event('frontend_entryproperties_query', $parts);
659659

660-
$_properties =& serendipity_db_query("SELECT property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$id . " " . $parts['and']);
660+
$_properties = serendipity_db_query("SELECT property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$id . " " . $parts['and']);
661661
if (!is_array($_properties)) {
662662
$properties = array();
663663
} else {
@@ -767,7 +767,7 @@ function &serendipity_fetchCategories($authorid = null, $name = null, $order = n
767767
$querystring .= "\n ORDER BY $order";
768768
}
769769

770-
$ret =& serendipity_db_query($querystring);
770+
$ret = serendipity_db_query($querystring);
771771
if (is_string($ret)) {
772772
echo "Query failed: $ret";
773773
} else {
@@ -950,7 +950,7 @@ function &serendipity_searchEntries($term, $limit = '', $searchresults = '') {
950950
ORDER BY {$cond['searchorderby']}
951951
$limit";
952952

953-
$search =& serendipity_db_query($querystring);
953+
$search = serendipity_db_query($querystring);
954954

955955
//Add param searchresults at the top and remove duplicates.
956956
if (is_array($searchresults)) {
@@ -1059,7 +1059,7 @@ function serendipity_getTotalEntries() {
10591059
if ($serendipity['fullCountQuery'] == '') {
10601060
return 0;
10611061
}
1062-
$query =& serendipity_db_query($querystring);
1062+
$query = serendipity_db_query($querystring);
10631063

10641064
if (is_array($query) && isset($query[0])) {
10651065
if ($serendipity['dbType'] == 'sqlite' || $serendipity['dbType'] == 'sqlite3' || $serendipity['dbType'] == 'pdo-sqlite' || $serendipity['dbType'] == 'sqlite3oo') {
@@ -1758,7 +1758,7 @@ function serendipity_printArchives() {
17581758
. (!empty($serendipity['GET']['viewAuthor']) ? ' AND e.authorid = ' . (int)$serendipity['GET']['viewAuthor'] : '')
17591759
. (!empty($cat_sql) ? " GROUP BY e.id, e.timestamp" : '');
17601760

1761-
$entries =& serendipity_db_query($q, false, 'assoc');
1761+
$entries = serendipity_db_query($q, false, 'assoc');
17621762

17631763
$group = array();
17641764
if (is_array($entries)) {

include/plugin_api.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ function &parseTemplate($filename)
17571757
* @param string The path selector that tells whether to return a HTTP or realpath
17581758
* @return string The full path+filename to the requested file
17591759
* */
1760-
function &getFile($filename, $key = 'serendipityPath')
1760+
function getFile($filename, $key = 'serendipityPath')
17611761
{
17621762
global $serendipity;
17631763

0 commit comments

Comments
 (0)