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 compatibility issue with array_merge #39579

Open
chazzs opened this issue Jan 28, 2025 · 6 comments
Open

PHP8 compatibility issue with array_merge #39579

chazzs opened this issue Jan 28, 2025 · 6 comments
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.x Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@chazzs
Copy link

chazzs commented Jan 28, 2025

When using \Magento\UrlRewrite\Model\StorageInterface::replace() when the url rewrite does not exist throws out ArgumentCountError: array_merge() does not accept unknown named parameters in .../vendor/magento/module-url-rewrite/Model/Storage/DbStorage.php:223

Code documentation for replace() reads Save new url rewrites and remove old if exist. this indicates that this function should succeed/finish (not throw an exception) if the URLrewrite does not currently exist.

is this an error or an error in code documentation? If it is an error in documentation should it not throw out a more meaningful exception rather than a core php error?

Copy link

m2-assistant bot commented Jan 28, 2025

Hi @chazzs. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@chazzs chazzs changed the title PHP8 compatability issue with array_merge PHP8 compatibility issue with array_merge Jan 28, 2025
@engcom-Bravo engcom-Bravo added Reported on 2.4.x Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it labels Jan 29, 2025
@github-project-automation github-project-automation bot moved this to Ready for Confirmation in Issue Confirmation and Triage Board Jan 29, 2025
@engcom-Hotel engcom-Hotel self-assigned this Jan 29, 2025
Copy link

m2-assistant bot commented Jan 29, 2025

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • 5. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Hotel
Copy link
Contributor

Hello @chazzs,

Thanks for the report and collaboration!

After going through the issue description it seems you are talking about the below interface:

interface StorageInterface extends UrlFinderInterface, UrlPersistInterface
{
}

which further extends UrlPersistInterface

/**
* Save new url rewrites and remove old if exist
*
* @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urls
* @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
* @throws \Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException|\Exception
*/
public function replace(array $urls);

But we need some more information on this issue as below:

  • Steps to reproduce
  • Actual and Expected result

Please provide us with the information.

Thanks

@engcom-Hotel engcom-Hotel added the Issue: needs update Additional information is require, waiting for response label Jan 29, 2025
@engcom-Hotel engcom-Hotel moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Jan 29, 2025
@chazzs
Copy link
Author

chazzs commented Jan 29, 2025

It should be pretty clear in the OP.

use \Magento\UrlRewrite\Model\StorageInterface;
use \Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
...
//this url rewrite does not exist.
$urw = new UrlRewrite([
    UrlRewrite::REQUEST_PATH => "some/request/path",
    UrlRewrite::TARGET_PATH => "some/target/path",
    UrlRewrite::ENTITY_TYPE => "some-type",
    UrlRewrite::ENTITY_ID => $some-id,
    UrlRewrite::STORE_ID => $some-store-id
]);

//will toss out the php argument error
$this->storageInterface->replace([$urw]);

the actual result is the error mentioned in the OP. the expected result is mentioned in the OP as well. it should basically be a No-op OR it should throw out an exception that is more meaningful than the "bad PHP" error. OR documentation should be updated to not imply that doing this with a URL rewrite that does not exist will not result in a core PHP error/exception.

I do no know enough about PHP to know how the fancy ellipsis as an argument works but, it seems PHP8 has significantly changed this behavior.

@engcom-Hotel
Copy link
Contributor

Hello @chazzs,

Thanks for the reply!

However, we cannot reproduce this issue in the latest 2.4-develop branch. We have tried to make a custom module and call the replace method for a non-existent path. But there is no fatal error shown on the console.

Please refer to this module:
YourVendor.zip

Please let us know if we missed anything.

Thanks

@chazzs
Copy link
Author

chazzs commented Jan 30, 2025

I am under a deadline and I had to devise a workaround first before taking the time to file the bug. I took a look through the edit history of the function i was working with and saw that if you do not provide the Entity ID(UrlRewrite::ENTITY_ID) item the exception gets thrown. Apologies for the confusion.

so from

//this url rewrite does not exist.
$urw = new UrlRewrite([
    UrlRewrite::REQUEST_PATH => "some/request/path",
    UrlRewrite::TARGET_PATH => "some/target/path",
    UrlRewrite::ENTITY_TYPE => "some-type",
    UrlRewrite::ENTITY_ID => $some-id,
    UrlRewrite::STORE_ID => $some-store-id
]);

to

//this url rewrite does not exist.
$urw = new UrlRewrite([
    UrlRewrite::REQUEST_PATH => "some/request/path",
    UrlRewrite::TARGET_PATH => "some/target/path",
    UrlRewrite::ENTITY_TYPE => "some-type",
    UrlRewrite::STORE_ID => $some-store-id
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.x Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

No branches or pull requests

3 participants