If memcached isn't running, the following message is generated:

Notice: Undefined variable: result in dmemcache_get() (line 114 of /var/www/sites/all/modules/contrib/memcache/dmemcache.inc).

This is because $result is defined within a test if ($mc || $mc = dmemcache_object($bin)) {, but returned outside the test without checking whether the test passed.

Moving $result to within the test suppresses the PHP notice, but doesn't alter the functionality (when the test condition fails, NULL will be returned in each case).

Comments

manarth’s picture

Status: Active » Needs review
StatusFileSize
new496 bytes

Patch attached.

manarth’s picture

Title: Surpress PHP Notice if cache not available » Suppress PHP Notice if cache not available
pillarsdotnet’s picture

Title: Suppress PHP Notice if cache not available » Fix Notice: Undefined variable: result in dmemcache_get() (line 114 of /var/www/sites/all/modules/memcache/dmemcache.inc).
StatusFileSize
new931 bytes

The function documentation says that it returns FALSE on error, which is different from NULL.

Attached patch solves the problem by initializing $result to FALSE.

das-peter’s picture

May I ask you to give this patch a review: #1184678: Enhance failure tolerance
If you get this error notice, it's likely you're also happy about the changes this patch makes :)
@pillarsdotnet: Thanks for "connecting" the patches.

pillarsdotnet’s picture

Status: Needs review » Closed (duplicate)