The MockTracer class provided by opentracing-php allows users to provide callables implementing tracing context injection for a given format. The inject() method implementation, when called with a given context, format and carrier, looks up the user-provided callable for the given format, and invokes it via PHP's call_user_func function to perform the injection.
Problem
This implementation is broken, because call_user_func passes parameters to the target by value rather than by reference.[1] Since the injection process relies on the carrier being passed by reference, so that the injection callable can modify the carrier, this will cause a PHP Warning and cause the injection to fail, e.g.:
Parameter 2 to OpenTracing\Tests\Mock\MockTracerTest::OpenTracing\Tests\Mock\{closure}() expected to be a reference, value given
Proposal
A solution is to have MockTracer invoke the callable directly, i.e.
Background
The
MockTracer
class provided by opentracing-php allows users to provide callables implementing tracing context injection for a given format. The inject() method implementation, when called with a given context, format and carrier, looks up the user-provided callable for the given format, and invokes it via PHP'scall_user_func
function to perform the injection.Problem
This implementation is broken, because
call_user_func
passes parameters to the target by value rather than by reference.[1] Since the injection process relies on the carrier being passed by reference, so that the injection callable can modify the carrier, this will cause a PHP Warning and cause the injection to fail, e.g.:Proposal
A solution is to have
MockTracer
invoke the callable directly, i.e.would become:
This would ensure that
$carrier
is passed by reference to the callable.[1] https://www.php.net/manual/en/function.call-user-func.php