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

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

Open
GuillaumeRossolini opened this issue Oct 8, 2018 · 1 comment

Comments

@GuillaumeRossolini
Copy link

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).

@francescozanoni
Copy link

francescozanoni commented Dec 15, 2019

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

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