ZFDebug icon indicating copy to clipboard operation
ZFDebug copied to clipboard

Fix for "Notice: A non well formed numeric value encountered" with v1.6.4

Open GuillaumeRossolini opened this issue 6 years ago • 1 comments

Hi,

In case anyone still uses this plugin, you will find below a fix for this error:

Notice: A non well formed numeric value encountered

Basically, the issue is that the plugin uses the same value both as an integer for substractions, and as a human-readable mark. that makes PHP v7.1+ show a Notice.

There are two places to fix in the Controller/Plugin/Debug/Plugin/Log.php file:

L120 should read: $this->_marks[$name]['time'] = round((microtime(true)-$_SERVER['REQUEST_TIME'])*1000-(int)$this->_marks[$name]['time']).'ms';

L122 should read: $this->_marks[$name]['memory'] = round((memory_get_usage()-(int)$this->_marks[$name]['memory'])/1024) . 'K';

This is admettedly an ugly fix. A better way could be to parse the value, preg_match it or even split the value in two, one for each purpose (calc or display).

GuillaumeRossolini avatar Oct 08 '18 16:10 GuillaumeRossolini

Hi.

As a temporary fix, I've created a script executed after any composer install or composer update:

// file path: scripts/fix_zfdebug.php

/**
 * ZFDebug fix for PHP >= 7.1 compatibility
 * 
 * @author Francesco Zanoni
 * @version 2019-12-15
 */

$libraryPath = __DIR__ . "/../vendor/jokkedk/zfdebug/library";

// Exception: count(): Parameter must be an array or an object that implements Countable
// jokkedk/zfdebug/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php on line 51
$filePath = $libraryPath . "/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php";
file_put_contents(
    $filePath,
    str_replace(
        '!count(',
        'empty(',
        file_get_contents($filePath)
    )
);

// Notice: A non well formed numeric value encountered
// jokkedk/zfdebug/library/ZFDebug/Controller/Plugin/Debug/Plugin/Log.php on line 119
$filePath = $libraryPath . "/ZFDebug/Controller/Plugin/Debug/Plugin/Log.php";
file_put_contents(
    $filePath,
    str_replace(
        '-$this->marks[$name][\'time\']',
        '-floatval($this->marks[$name][\'time\'])',
        file_get_contents($filePath)
    )
);

// Notice: A non well formed numeric value encountered
// jokkedk/zfdebug/library/ZFDebug/Controller/Plugin/Debug/Plugin/Log.php on line 121
$filePath = $libraryPath . "/ZFDebug/Controller/Plugin/Debug/Plugin/Log.php";
file_put_contents(
    $filePath,
    str_replace(
        '-$this->marks[$name][\'memory\']',
        '-intval($this->marks[$name][\'memory\'])',
        file_get_contents($filePath)
    )
);

And here's the related composer.json section:

{
  "require-dev": {
    "jokkedk/zfdebug": "^1.6",
  },
  "scripts": {
    "post-install-cmd": [
      "php scripts/fix_zfdebug.php"
    ]
  }
}

Hope this helps.

Francesco

francescozanoni avatar Dec 15 '19 09:12 francescozanoni