-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
Some changes for compatibility with PHP 8.1 #1812
Conversation
maybe split the PR up a bit type of changes, the size looks already like it needs an hour to properly Review for me. |
Not sure how to proceed. |
@luigifab First of all sorry that I overlooked this PR before creating #1891. But I have a question regarding your solution for the deprecation notices in Commit 1 fix. |
Oh yes, you are right, I don't remember why I didn't do that. Your solution is better. |
@@ -101,7 +101,7 @@ public function loadToXml(Mage_Core_Model_Config $xmlConfig, $condition = null) | |||
if ($r['scope'] !== 'default') { | |||
continue; | |||
} | |||
$value = str_replace($substFrom, $substTo, $r['value']); | |||
$value = empty($r['value']) ? $r['value'] : str_replace($substFrom, $substTo, $r['value']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added empty-check must also be applied to line 121 and 150 for website and store scope, respectively.
…string) of type string is deprecated
…parameter #2 ($cursorOrientation) of type int is deprecated
…#3 ($subject) of type array|string is deprecated
…($string) of type string is deprecated
…($haystack) of type string is deprecated
…#1 ($string) of type string is deprecated
…ameter #1 ($string) of type string is deprecated
…string) of type string is deprecated
…string) of type string is deprecated
…($string) of type string is deprecated
…($haystack) of type string is deprecated
…#2 ($replace) of type array|string is deprecated
… ($datetime) of type string is deprecated
…string) of type string is deprecated
@@ -214,7 +214,7 @@ public function removeClass($class) | |||
*/ | |||
protected function _escape($string) | |||
{ | |||
return htmlspecialchars($string, ENT_COMPAT); | |||
return is_string($string) ? htmlspecialchars($string, ENT_COMPAT) : $string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I'm happy with your PR mainly relying on added typechecks to avoid problems with PHP 8.1. But in this case I would like to argue that an explicit cast to string htmlspecialchars((string)$string, ENT_COMPAT)
would be more appropriate to use (because we don't want to introduce parameter types here to avoid breaking things).
The method clearly escapes a string, the parameter name and the phpdoc type point in that direction. While a is_string
is not taxing the check will be performed a lot of times judging by its location in Varien Lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest
return htmlspecialchars((string)$string, ENT_COMPAT);
While working on OpenMage compatibility with PHP 8.1 myself, I'm using this PR as a reference, but have encountered additional errors that are similar in nature and not part of any custom code of the OM instance. Would you say we extend this PR further (it's still a draft after all but on the other hand already quite heavy) or should I provide complementary PRs? |
You can create a new PR to replace this PR, or multiple PR, as you want. |
@@ -140,8 +140,8 @@ public function getStoreLastLoginDateTimezone() | |||
public function getCurrentStatus() | |||
{ | |||
$log = $this->getCustomerLog(); | |||
if ($log->getLogoutAt() || | |||
strtotime(now())-strtotime($log->getLastVisitAt())>Mage_Log_Model_Visitor::getOnlineMinutesInterval()*60) { | |||
if ($log->getLogoutAt() || (!empty($log->getLastVisitAt()) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix removes the deprecation error but introduces a bug. Up to the fix the behavior has been that strtotime(null)
evaluates to false
so nothing is subtracted (false = 0) from strtotime(now())
and the 2nd condition evaluates to true so 'offline' is returned. With your fix in those cases the method returns 'online'
.
Your solution displays:
before:
I fixed it by combining your check with correctly executing the subtraction:
if ($log->getLogoutAt()
|| strtotime(now()) - (!empty($log->getLastVisitAt()) ? strtotime($log->getLastVisitAt()) : 0) > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60) {
return Mage::helper('customer')->__('Offline');
}
Today I see that: |
Also gmstrftime . |
@luigifab thanks for your great work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please cast value when passing to strtolower, in php7 strtolower was always converting value to string. see https://3v4l.org/J7S66
@@ -421,7 +421,8 @@ public static function getStoreConfig($path, $store = null) | |||
*/ | |||
public static function getStoreConfigFlag($path, $store = null) | |||
{ | |||
$flag = strtolower(self::getStoreConfig($path, $store)); | |||
$flag = self::getStoreConfig($path, $store); | |||
$flag = is_string($flag) ? strtolower($flag) : $flag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$flag = strtolower((string)self::getStoreConfig($path, $store));
There is an error in this PR, and I didn't work on it... |
@luigifab great stuff! ❤️ (for the next time ... please split it into smaller junks to make reviews easier. I know it from my own (large) PRs ... smaller PRs are reviewed/merged faster) |
Description
Not sure if all changes are the best or not.
PHP 8.0.11 and 8.1.0-rc2 (from deb.sury.org).
Manual testing scenario
First, disable Suppress deprecation warnings in app/code/core/Mage/Core/functions.php:
Go to your backend login page, login, go to dashboard, then enable PHP 8.1, clear your cache, and press F5.
Commit 1 fix:
Apply commit 1, then press F5.
Commit 2 fix:
Solution found here: matomo-org/matomo#17689
Apply commit 2, then press F5.
Commit 3 fix:
Apply commit 3, then press F5.
Dashboard is displayed.
Clear your cache and your log directory, then press F5.
Commit 4 fix (exception.log):
Apply commit 4, then press F5.
Clear your cache and your log directory, then press F5.
Go to Sales / Order.
Commit 5 fix:
Apply commit 5, then press F5.
Commit 6 fix:
Apply commit 6, then press F5.
Commit 7 fix:
TODO Make a PR for zf1-future.
Apply commit 7, then press F5.
Commit 8 fix:
Apply commit 8, then press F5.
Commit 9 fix:
Apply commit 9, then press F5.
Commit 10 fix:
Apply commit 10, then press F5.
Commit 11 fix:
Apply commit 11, then press F5.
Orders grid is displayed.
Click on Export to CSV button.
Commit 12 fix:
Apply commit 12, then press F5.
Back to Sales / Order.
Filter grid and reset filter.
Sort grid.
Go to any pending order.
Commit 13 fix:
Apply commit 13, then press F5.
Commit 14 fix:
Apply commit 14, then press F5.
Order is displayed.
Click on Invoice button.
Commit 15 fix:
TODO Make a PR for zf1-future.
Apply commit 15, then press F5.
Commit 16 fix:
Apply commit 16, then press F5.
New Invoice for Order is displayed.
Set quantity to invoice to 0 and press Update Qty button.
TODO There is an hidden error.
Click on Submit invoice button.
Click on Ship button.
Click on Submit shipment button.
Click on Credit memo button.
Set quantity to refund to 0 and press Update Qty button.
Click on Refund offline button.
Click on Credit memo button.
Click on Refund offline button.
Go to Sales / Invoice.
Click on export to CSV button.
Filter grid and reset filter.
Sort grid.
Go to any invoice.
Go to Sales / Shipment.
Click on export to CSV button.
Filter grid and reset filter.
Sort grid.
Go to any shipment.
Go to Sales / Credit memos.
Click on export to CSV button.
Filter grid and reset filter.
Sort grid.
Go to any credit memo.
Go to Sales / Order, click on Create New Order.
Commit 17 fix:
Apply commit 17, then press F5.
Commit 18 fix:
Apply commit 18, then press F5.
Commit 19 fix:
Apply commit 19, then press F5.
Create new order is displayed.
Filter grid and reset filter.
Sort grid.
Select a customer and select a store view.
Add a product and select a shipping method.
Click on Submit order button.
Order is displayed.
Click on Cancel button.
Click on Reorder button.
Click on Submit order button.
Go to Sales / Terms and Conditions.
Filter grid and reset filter.
Sort grid.
Click on Add new button.
Commit 20 fix:
Apply commit 20, then press F5.
New Terms and Conditions is displayed.
Fill the form and click on Save condition button.
Reboot your computer.
Go to Sales / Order.
Commit 21 fix:
Apply commit 21, then press F5.
Open a complete order.
Commit 22 fix:
Apply commit 22, then press F5.
Go to Sales / Tax / Import Export.
Click on Export.
Commit 23 fix:
Apply commit 23, then press F5.
Go to Customers / Customers.
Go to any customer.
Commit 24 fix:
Apply commit 24, then press F5.
Commit 25 fix:
Apply commit 25, then press F5.
Customer edit is displayed.
Go to dashboard.
Commit 26 fix:
Apply commit 26, then press F5.
Contribution checklist