Skip to content

Warning: call_user_func() expects parameter 1 to be a valid callback, cannot access protected method #92

@rhelms

Description

@rhelms

I've recently updated a project from PHP 7.0 to PHP 7.2 that uses antecent/patchwork to allow me to mock particular functions. Under PHP 7.0, this was working well, but under PHP 7.2 I get the following warnings.

PHP Warning: call_user_func() expects parameter 1 to be a valid callback, cannot access protected method PhpAmqpLib\Channel\AMQPChannel::channel_close_ok() in /var/www/api/vendor/antecedent/patchwork/src/CallRerouting.php(447) : eval()'d code on line 20

PHP Warning: call_user_func() expects parameter 1 to be a valid callback, cannot access protected method PhpAmqpLib\Connection\AMQPConnection::connection_close_ok() in /var/www/api/vendor/antecedent/patchwork/src/CallRerouting.php(447) : eval()'d code on line 20

When updating from 7.0 to 7.2, the php-amqplib/php-amqplib dependency was updated from v2.8.1 to v2.9.2. As far as I can tell the channel_close_ok and connection_close_ok functions mentioned have always been protected functions, and both functions are defined on classes that extend abstract classes.

The project is using patchwork 2.1.8.

The initial issue is that I can't tell how the eval is getting invoked for these functions in the first place. The eval location at line 447 at CallRerouting.php is a part of createStubsForInternals. The $name used in the eval should be coming from Config\getRedefinableInternals() which is the list of default internals (from Config.php) and any items in the patchwork.json, in the redefinable-internals section, for which I have syslog and sleep.

Unless the issue is that it's call_user_func that has been redefined by the in the rerouting, and the phpamqplib code base is using call_user_func to run the protected functions, and it can't because the it isn't being run from the same namespace as the protected functions.

Have I hit a limitation in patchwork with regards to how call_user_func may get used to call protected functions in third party libraries?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions