Skip to content

Conversation

@Litarnus
Copy link
Contributor

@Litarnus Litarnus commented Oct 9, 2025

Replaces the usage of str_starts_with in our vendored ClockMock with strpos to remain PHP 7.2 compatible.

It currently only works because we are using polyfill through symfony/options-resolver, which will be removed in the future and will cause this code to fail.

@Litarnus Litarnus self-assigned this Oct 9, 2025
@Litarnus Litarnus marked this pull request as ready for review October 9, 2025 13:56
@Litarnus Litarnus requested a review from cleptric October 9, 2025 13:56
@Litarnus Litarnus mentioned this pull request Oct 9, 2025
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
} elseif (str_starts_with($class, 'Tests\\')) {
} elseif (strpos($class, 'Tests\\') === 0) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential bug: This change is an incomplete fix. Other calls to PHP 8+ functions like str_starts_with remain, which will cause fatal errors on older PHP versions.
  • Description: The change at src/Util/ClockMock.php correctly replaces a PHP 8.0+ function call. However, this fix is incomplete. The codebase still contains calls to str_starts_with (in FrameBuilder.php) and str_contains (in DynamicSamplingContext.php). The PR author's belief that a polyfill is provided by symfony/options-resolver is incorrect. Since the project supports PHP 7.2+ and lacks a proper polyfill, these calls will cause fatal 'Call to undefined function' errors on PHP 7.2-7.4, crashing the application when processing stack traces or tracing headers.

  • Suggested fix: Apply the same fix pattern to the remaining instances. Replace str_starts_with in FrameBuilder.php and str_contains in DynamicSamplingContext.php with PHP 7-compatible alternatives. Alternatively, add the symfony/polyfill-php80 dependency to provide these functions on older PHP versions.
    severity: 0.9, confidence: 0.95

Did we get this right? 👍 / 👎 to inform future reviews.

@Litarnus Litarnus merged commit 1de5202 into master Oct 13, 2025
39 checks passed
@Litarnus Litarnus deleted the martinl/remove-starts-with branch October 13, 2025 07:47
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

Successfully merging this pull request may close these issues.

3 participants