We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

random BadMethodCallExceptions

After upgrading to Phalcon 2.0.8 from 1.3 I started getting seemingly random BadMethodCallExceptions exceptions from across my code:

Fatal error: Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters'

For example, I get this:

Fatal error: Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters' in /srv/www/laffo/drywall/vendor/phalcon/incubator/Library/Phalcon/Logger/Adapter/Firelogger.php on line 205 BadMethodCallException: Wrong number of parameters in /srv/www/laffo/drywall/vendor/phalcon/incubator/Library/Phalcon/Logger/Adapter/Firelogger.php on line 205 Call Stack: 0.0833 2681632 1. Phalcon\Logger\Adapter\Firelogger->commit() /srv/www/laffo/drywall/vendor/phalcon/incubator/Library/Phalcon/Logger/Adapter/Firelogger.php:0 0.0833 2681632 2. Phalcon\Logger\Adapter\Firelogger->flush() /srv/www/laffo/drywall/vendor/phalcon/incubator/Library/Phalcon/Logger/Adapter/Firelogger.php:191 0.0833 2682088 3. trigger_error() /srv/www/laffo/drywall/vendor/phalcon/incubator/Library/Phalcon/Logger/Adapter/Firelogger.php:205

Firelogger is from the incubator library, version ~2.0. On line #205 there is this code:

        trigger_error(

"Cannot send FireLogger headers after output has been sent" . ($file ? " (output started at $file:$line)." : "."), \E_USER_WARNING );

There is nothing wrong with this code, and I don't think it's a problem with incubator. I am getting the same BadMethodCallException at other places too, for example when calling \Phalcon\Mvc\Model::create() method with no arguments (e.g. $myModel->create();). Whether I get the exception depends on WHEN I call whatever code that has triggered the exception. For example, if I put

trigger_error('someting', \E_USER_WARNING);

into index.php, it works fine, no exception. I suspect this is a bug in Phalcon 2.0.x but before filing it at github I wanted to check if anybody else has encoutered this weirdness. Any ideas anyone please?

As a temporary fix I changed this in Firelogger:

try {                
    trigger_error(
       "Cannot send FireLogger headers after output has been sent" .
       ($file ? " (output started at $file:$line)." : "."),
       \E_USER_WARNING
    );
} catch (\BadMethodCallException $e) {
    // this is a buggy exception
} catch (\Exception $e) {
    throw $e;
}

This is far from ideal though. I would like to address root of the issue. Calling trigger_error should not be throwing an exception like this.



3.1k
Accepted
answer

After digging into the problem, I found the source of the problem. I dumped the stack trace in the catch block, the first node reads:

function: onUncaughtLowSeverity
class: Phalcon\\Debug
type: ->

That points to Phalcon\Debug. I have this in my services.php:

$debug = new \Phalcon\Debug();
$debug->listen(true, true);
// this is the same as
// $debug->listeneExceptions;
// $debug->listenLowSeverity();

If I disable listening for unsilent low severity errors (warnings, notices), the problem goes away. I'm filing a bug. The workaround for now is not to use the Debug component for listening for low severity errors:

$debug->listen(true, false);