-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid resolving unresolved functions and classes (#2450)
This only may pose problems with DDTrace\Trace attributes. In theory having the hook installed twice should not pose problems, but adding a hook to an unresolved class is at the very least not a supported scenario. Checking for the classes being actually linked. This only affects PHP 8.0 and PHP 8.1. Signed-off-by: Bob Weinand <[email protected]>
- Loading branch information
Showing
3 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--TEST-- | ||
Test delayed resolution of tracing attributes | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 80000) die('skip: No attributes pre-PHP 8'); ?> | ||
--ENV-- | ||
DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
--FILE-- | ||
<?php | ||
|
||
include __DIR__ . '/sandbox/dd_dumper.inc'; | ||
|
||
$eval = <<<'EVAL' | ||
eval("class Bar {}"); | ||
class Foo extends Bar { | ||
#[DDTrace\Trace(name: "simpleclass")] | ||
static function simple($arg) { return $arg; } | ||
} | ||
EVAL; | ||
|
||
$oldId = DDTrace\install_hook("somefunction", function() {}); | ||
eval($eval); | ||
$newId = DDTrace\install_hook("somefunction", function() {}); | ||
|
||
Foo::simple(1); | ||
|
||
var_dump($newId - $oldId - 1); // we check how many hooks were installed in between, to ensure that it was installed only once | ||
|
||
$eval = <<<'EVAL' | ||
if (time()) { | ||
#[DDTrace\Trace(name: "simplefunc")] | ||
function simple($arg) { return $arg; } | ||
} | ||
EVAL; | ||
|
||
$oldId = DDTrace\install_hook("somefunction", function() {}); | ||
eval($eval); | ||
$newId = DDTrace\install_hook("somefunction", function() {}); | ||
|
||
simple(1); | ||
|
||
var_dump($newId - $oldId - 1); // we check how many hooks were installed in between, to ensure that it was installed only once | ||
|
||
dd_dump_spans(); | ||
|
||
?> | ||
--EXPECTF-- | ||
int(1) | ||
int(1) | ||
spans(\DDTrace\SpanData) (2) { | ||
simpleclass (traced_attribute_delayed.php, simpleclass, cli) | ||
_dd.p.dm => -0 | ||
_dd.p.tid => %s | ||
simplefunc (traced_attribute_delayed.php, simplefunc, cli) | ||
_dd.p.dm => -0 | ||
_dd.p.tid => %s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters