Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated functionality: preg_match(): Passing null to parameter #4 … #4251

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

addison74
Copy link
Contributor

...($flags) of type int is deprecated.

[Test Environment]

  • Windows 11 + WSL
  • Docker 4.34.2
  • DDEV (Apache 2.4.61, PHP 8.3.10, MariaDB 10.11.8) with MAGE_IS_DEVELOPER_MODE=1
  • Magento Sample Data

Go the Backend > System > Configuration > Advanced > Developer > Translate Inline. Set "Enablde for Admin" to Yes and save. Here is the error message you will see in the browser page

Deprecated functionality: preg_match(): Passing null to parameter #4 ($flags) of type int is deprecated  in /var/www/html/app/code/core/Mage/Core/Model/Translate/Inline.php on line 521

#0 [internal function]: mageCoreErrorHandler()
#1 /var/www/html/app/code/core/Mage/Core/Model/Translate/Inline.php(521): preg_match()
#2 /var/www/html/app/code/core/Mage/Core/Model/Translate/Inline.php(463): Mage_Core_Model_Translate_Inline->findEndOfTag()
#3 /var/www/html/app/code/core/Mage/Core/Model/Translate/Inline.php(404): Mage_Core_Model_Translate_Inline->_translateTags()
#4 /var/www/html/app/code/core/Mage/Core/Model/Translate/Inline.php(223): Mage_Core_Model_Translate_Inline->_specialTags()
#5 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Action.php(389): Mage_Core_Model_Translate_Inline->processResponseBody()
#6 /var/www/html/app/code/core/Mage/Adminhtml/controllers/DashboardController.php(37): Mage_Core_Controller_Varien_Action->renderLayout()
#7 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Adminhtml_DashboardController->indexAction()
#8 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(255): Mage_Core_Controller_Varien_Action->dispatch()
#9 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Front.php(180): Mage_Core_Controller_Varien_Router_Standard->match()
#10 /var/www/html/app/code/core/Mage/Core/Model/App.php(358): Mage_Core_Controller_Varien_Front->dispatch()
#11 /var/www/html/app/Mage.php(748): Mage_Core_Model_App->run()
#12 /var/www/html/index.php(56): Mage::run()
#13 {main}

From now on you cannot access the Backend. You have to change in the database > table core_config_data > "dev/translate_inline/active_admin" from 1 to 0 in the "path" column.

if (preg_match('#<\\\\?\/' . $tagName . '\s*?>#i', $body, $tagMatch, null, $end))

This issue can be reproduced starting with PHP version 8.1. It is strange how it was not discovered by the GitHub tests.

…($flags) of type int is deprecated

- This PR fixes #4250.
@github-actions github-actions bot added the Component: Core Relates to Mage_Core label Oct 6, 2024
@addison74
Copy link
Contributor Author

addison74 commented Oct 6, 2024

I chose the implementation from Twig, but there are other solutions that propose using PREG_UNMATCHED_AS_NULL as a flag.

PREG_UNMATCHED_AS_NULL = This flag tells preg_match() and preg_match_all() to include unmatched subpatterns in $matches as null values. Without this flag, unmatched subpatterns are reported as empty strings, as if they were empty matches. Setting this flag allows to distinguish between these two cases.

Copy link
Contributor

github-actions bot commented Oct 6, 2024

Test Results

250 tests  ±0   250 ✅ ±0   2s ⏱️ ±0s
 71 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 0cbe06e. ± Comparison against base commit 2c1626e.

♻️ This comment has been updated with latest results.

@sreichel sreichel merged commit df37dba into main Oct 8, 2024
36 checks passed
@sreichel sreichel deleted the ADDISON74-inline-deprecated branch October 8, 2024 23:09
@sreichel
Copy link
Contributor

sreichel commented Oct 14, 2024

It is strange how it was not discovered by the GitHub tests.

This should be covered now by PHPStan Level 5 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Relates to Mage_Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecated functionality: preg_match(): Passing null to parameter #4 ($flags) of type int is deprecated
3 participants