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

[php8.1] deprecated passing null to str_replace() , ref #1812 #2806

Closed
wants to merge 2 commits into from
Closed

[php8.1] deprecated passing null to str_replace() , ref #1812 #2806

wants to merge 2 commits into from

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented Dec 12, 2022

Description (*)

Related Pull Requests

  1. Some changes for compatibility with PHP 8.1 #1812
  2. [PHP 8.1] Fix passing null to non-nullable internal function params #2586

Fixed Issues (if relevant)

Deprecated functionality: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in app/code/core/Mage/Core/Model/Resource/Config.php on line 104

Questions or comments

Fixed bit different. Set no default value when value from DB is NULL.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@github-actions github-actions bot added the Component: Core Relates to Mage_Core label Dec 12, 2022
@sreichel sreichel marked this pull request as draft December 12, 2022 22:00
@sreichel sreichel marked this pull request as ready for review December 12, 2022 22:10
@sreichel sreichel added the PHP 8.1 Related to PHP 8.1 label Dec 12, 2022
@@ -133,7 +133,7 @@ public function loadToXml(Mage_Core_Model_Config $xmlConfig, $condition = null)
$deleteStores = [];
// set stores config values from database
foreach ($rowset as $r) {
if ($r['scope'] !== 'stores') {
if (is_null($r['value']) || $r['scope'] !== 'stores') {
Copy link
Contributor

@kiatng kiatng Dec 13, 2022

Choose a reason for hiding this comment

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

Didn't test, but in PHP7, if (is_null($r['value']) then $value = empty string, and it would continue to line 40. Shouldn't PHP8 do the same?

Copy link
Contributor Author

@sreichel sreichel Dec 14, 2022

Choose a reason for hiding this comment

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

Can you please test it?

Your right, this changes some behavoir ... we dont set empty nodes ...

Test

  • set some config to null in DB (i've used Title Prefix form Admin -> Design config)
  • load/save config
  • set debug breakpoint at Varien_Simplexml_Config::setNode()

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll look into it after my holiday.

Copy link
Contributor Author

@sreichel sreichel Dec 15, 2022

Choose a reason for hiding this comment

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

and it would continue to line

Right, but there we just create an empty XML-node for a null DB value.

With this change the node is not created. What could happen? Access a not-existing node (getConfigNode() or getNode())? Did not found any errors yet.

I could be an improvement to not create emtpy xml-nodes, but needs some testing ...

I'll open a new PR with casting to string to move forward. This can be investigated later. :)

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking of an edge case which I'm not sure if it exists or not: What if there's a config that has a default value in xml config file and you clear the value from Admin panel, so it tries to save null in the database but that won't happen. So it will keep using the default value in xml file. Please let's investigate this before proceeding.

Copy link
Contributor Author

@sreichel sreichel Jan 4, 2023

Choose a reason for hiding this comment

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

@elidrissidev tested this and everything looks fine. (Method description says Load configuration values into xml config object and we just avoid loading null to config object.)

Edit:

Default valuew from config.xml are only used when no config path exists in core_config_data. It is not used when a null entry exists in DB.

If i did not wrong this PR works as it should,

Copy link
Member

@elidrissidev elidrissidev Jan 6, 2023

Choose a reason for hiding this comment

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

Default valuew from config.xml are only used when no config path exists in core_config_data. It is not used when a null entry exists in DB.

@sreichel where did you see that it's not used if value in db is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested it.

Copy link
Member

Choose a reason for hiding this comment

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

I have tested this by setting contacts/email/recipient_email to NULL in db (it has default value of "hello@ example.com" in xml), and then running:

Mage::app()->getConfig()->getNode('default/contacts/email/recipient_email')

I could see that before adding the is_null($r['value']) check, it was returning an empty string value, whereas after that it's returning the value from xml. So might not be totally safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Tested getConfigNode() at the beginning - w/o default config value.

@sreichel sreichel marked this pull request as draft December 13, 2022 21:15
@sreichel sreichel marked this pull request as ready for review January 3, 2023 23:57
@sreichel
Copy link
Contributor Author

sreichel commented Jan 4, 2023

This is the first error i see, when testing php8.1 and dont supress errors.

Review needed. See comments above.

@sreichel sreichel added needs investigation review needed Problem should be verified and removed needs investigation labels Jan 4, 2023
@sreichel sreichel closed this by deleting the head repository Jan 8, 2023
@ADDISON74 ADDISON74 reopened this Jan 9, 2023
@sreichel
Copy link
Contributor Author

sreichel commented Jan 9, 2023

Better use #2901

@sreichel sreichel closed this Jan 9, 2023
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 PHP 8.1 Related to PHP 8.1 review needed Problem should be verified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants