Skip to content

[Magento 2.4.4] Class Magento\Framework\Profiler\Driver\Standard\Stat not compatible with PHP 8.1 #35307

@guvra

Description

@guvra

Preconditions (*)

  1. Magento 2.4.4

Steps to reproduce (*)

  1. In a custom module (in our case, a debug toolbar), call the method getFilteredTimerIds of the class Magento\Framework\Profiler\Driver\Standard\Stat.

Expected result (*)

  1. The function returns an array of ordered timer ids

Actual result (*)

  1. PHP crashes with the following error :
1 exception(s):
Exception #0 (Exception): Deprecated Functionality: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/html/vendor/magento/framework/Profiler/Driver/Standard/Stat.php on line 213

Exception #0 (Exception): Deprecated Functionality: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/html/vendor/magento/framework/Profiler/Driver/Standard/Stat.php on line 213
<pre>#1 strpos() called at [vendor/magento/framework/Profiler/Driver/Standard/Stat.php:213]
#2 Magento\Framework\Profiler\Driver\Standard\Stat->_getOrderedTimerIds() called at [vendor/magento/framework/Profiler/Driver/Standard/Stat.php:158]
#3 Magento\Framework\Profiler\Driver\Standard\Stat->getFilteredTimerIds() called at [app/code/Smile/DebugToolbar/Helper/Profiler.php:96]
#4 Smile\DebugToolbar\Helper\Profiler->prepareTimers() called at [app/code/Smile/DebugToolbar/Helper/Profiler.php:68]
#5 Smile\DebugToolbar\Helper\Profiler->computeStats() called at [app/code/Smile/DebugToolbar/Observer/AddToolbar.php:105]
#6 Smile\DebugToolbar\Observer\AddToolbar->execute() called at [vendor/magento/framework/Event/Invoker/InvokerDefault.php:88]
#7 Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod() called at [vendor/magento/framework/Event/Invoker/InvokerDefault.php:74]
#8 Magento\Framework\Event\Invoker\InvokerDefault->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#9 Magento\Framework\Event\Invoker\InvokerDefault\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#10 Magento\Framework\Event\Invoker\InvokerDefault\Interceptor->Magento\Framework\Interception\{closure}() called at [app/code/Smile/DebugToolbar/Plugin/Event/Invoker.php:64]
#11 Smile\DebugToolbar\Plugin\Event\Invoker->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#12 Magento\Framework\Event\Invoker\InvokerDefault\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#13 Magento\Framework\Event\Invoker\InvokerDefault\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/Event/Invoker/InvokerDefault/Interceptor.php:23]
#14 Magento\Framework\Event\Invoker\InvokerDefault\Interceptor->dispatch() called at [vendor/magento/framework/Event/Manager.php:66]
#15 Magento\Framework\Event\Manager->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#16 Magento\Framework\Event\Manager\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#17 Magento\Framework\Event\Manager\Interceptor->Magento\Framework\Interception\{closure}() called at [app/code/Smile/DebugToolbar/Plugin/Event/Manager.php:52]
#18 Smile\DebugToolbar\Plugin\Event\Manager->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#19 Magento\Framework\Event\Manager\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#20 Magento\Framework\Event\Manager\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/Event/Manager/Interceptor.php:23]
#21 Magento\Framework\Event\Manager\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.php:131]
#22 Magento\Framework\App\Http->launch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#23 Magento\Framework\App\Http\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#24 Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#25 Magento\Framework\App\Http\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23]
#26 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#27 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:30]
</pre>

The error happens in the protected method _getOrderedTimerIds:

for ($j = $i + 1; $j < count($timerIds); $j++) {
    if (strpos($timerIds[$j], $prevTimerId . Profiler::NESTING_SEPARATOR) === 0) {
        $result[] = $timerIds[$j];
        /* Mark timer as already added */
        $timerIds[$j] = null;
    }
}

$timerIds[$j] is set to null at line 216, so the call to strpos at line 210 fails (strpos only accepts string values in PHP 8.1).


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Area: FrameworkIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P1Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing.Progress: doneReported on 2.4.4Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions