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

ScalarizeArray should be able to deal with ArrayAccess #6668

Open
codedge opened this issue May 31, 2023 · 1 comment
Open

ScalarizeArray should be able to deal with ArrayAccess #6668

codedge opened this issue May 31, 2023 · 1 comment

Comments

@codedge
Copy link

codedge commented May 31, 2023

The scalarizeArray method deals internally with values of type array OR objects with ArrayAccessible interface (see code). But when recursively called and an object with ArrayAccess occurs, it fails due to only array is allowed as type.

For example if you pass a doctrine ArrayCollection you get

 [TypeError] Codeception\Module::scalarizeArray(): Argument #1 ($array) must be of type array, Doctrine\Common\Collections\ArrayCollection given, called in /var/www/html/vendor/codeception/codeception/src/Codeception/Module.php on line 317

as an error back.

Should the method signature be protected function scalarizeArray(ArrayAccess|array $array): ArrayAccess|array to be ready for both types? Otherwise your check (is_array($v) || $v instanceof ArrayAccess) does not make much sense.

This seems to be a problem from PHP 8.2 on.

  • Codeception version: 5.0.3
  • PHP Version: 8.2
  • Operating System: Linux
  • Installation type: Composer
  • List of installed packages (composer show)
@Naktibalda
Copy link
Member

I think that scalarizeArray should be moved to REST module, because it is the only module that is using this method.
scalarizeArray in Codeception\Module can be marked as @deprecated to avoid breaking some 3rd party module in patch release.

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

No branches or pull requests

2 participants