s9y / Serendipity

A PHP blog software
https://s9y.org
BSD 3-Clause "New" or "Revised" License
209 stars 88 forks source link

Warning about passing NULL to PDO->quote() #813

Closed hannob closed 1 year ago

hannob commented 1 year ago

I'm getting warnings in the backend with PHP 8.2 and GIT head (using sqlite) like this:

Notice: PDO::quote(): Passing null to parameter #1 ($string) of type string is deprecated in [...]/htdocs/include/db/pdo-sqlite.inc.php on line 122.

It only happens on first load of the backend interface. To reproduce, I need to clear the templates_c directory.

Here' s a stack trace:


#0 [internal function]: errorToExceptionHandler(8192, '...', '...', 122)
#1 [...]/include/db/pdo-sqlite.inc.php(122): PDO->quote(NULL)
#2 [...]/include/db/db.inc.php(85): serendipity_db_escape_string(NULL)
#3 [...]/include/plugin_api.inc.php(849): serendipity_db_insert('...', Array)
#4 [...]/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php(867): serendipity_plugin_api::setPluginInfo(Array, '...', 1, 1, '...')
#5 [...]/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php(1164): serendipity_event_spartacus->buildList(Array, '...')
#6 [...]/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php(1340): serendipity_event_spartacus->count_plugin_upgrades()
#7 [...]/include/plugin_api.inc.php(1188): serendipity_event_spartacus->event_hook('...', Object(serendipity_property_bag), '', NULL)
#8 [...]/include/admin/overview.inc.php(66): serendipity_plugin_api::hook_event('...', '')
#9 [...]/serendipity_admin.php(214): include('...')
onli commented 1 year ago

Can you confirm that line 122 in your installation looks like this:

return substr($serendipity['dbConn']->quote($string ?? ''), 1, -1);

Because the ?? '' was added to avoid the message and seems correct to me. But if the warning appeared only once anyway the change might have been ineffective and I'm missing something...

hannob commented 1 year ago

I don't see that code. Line 122: https://github.com/s9y/Serendipity/blob/master/include/db/pdo-sqlite.inc.php#L122 currently says:

    return substr($serendipity['dbConn']->quote($string), 1, -1);

But I can confirm that changing the code to your version fixes the issue. Maybe you made the change locally and haven't committed it yet?

onli commented 1 year ago

Maybe you made the change locally and haven't committed it yet?

Exactly :/ I pushed them now, https://github.com/s9y/Serendipity/commit/d3f6e74b556b6d03b08331125fc2aaa9ed18738d

hannob commented 1 year ago

So we're done here.