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

Fixing PHP Warning - count(): Parameter must be an array or an object… #8448

Merged
merged 3 commits into from Feb 17, 2020

Conversation

escopecz
Copy link
Sponsor Member

Please be sure you are submitting this against the staging branch.

Q A
Bug fix? Y
New feature? N
Automated tests included? Y
Related user documentation PR URL /
Related developer documentation PR URL /
Issues addressed (#s or URLs) /
BC breaks? N
Deprecations? N

Description:

PHP 7.2+ has problem with count(null) ant throws this:

Symfony\Component\Debug\Exception\ContextErrorException: PHP Warning - count(): Parameter must be an array or an object that implements Countable
in /app/bundles/CoreBundle/Model/IteratorExportDataModel.php:71

This PR ensures that count will be called only with countable.

Steps to reproduce the bug:

  1. The error happens on contact export, but it may happen only under special unknown conditions.

Steps to test this PR:

  1. I was able to reproduce it in the attached unit test. Ensure that the tests are passing on Travis.

… that implements Countable

in IteratorExportDataModel.php:71
@escopecz escopecz self-assigned this Feb 17, 2020
@escopecz escopecz added bug Issues or PR's relating to bugs Mautic 3 labels Feb 17, 2020
@escopecz escopecz added this to the 3.0.0 milestone Feb 17, 2020
@escopecz escopecz added this to Needs code review and/or test in Mautic 3 Feb 17, 2020
$this->total = $this->total + count($this->data);
$this->totalResult = count($this->data);
$this->totalResult = $this->data ? count($this->data) : 0;
$this->total = $this->total + $this->totalResult;
$this->position = 0;
++$this->page;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please remove this line. Variable is not used and it's producing

PHP Notice - Undefined property: Mautic\CoreBundle\Model\IteratorExportDataModel::$page" at /Users/lukas.drahy/dev/community-fork/app/bundles/CoreBundle/Model/IteratorExportDataModel.php line 66

for me now.

@hluchas
Copy link
Contributor

hluchas commented Feb 17, 2020

can be merged

@anton-vlasenko
Copy link
Contributor

@escopecz

@escopecz escopecz merged commit 3276681 into mautic:3.x Feb 17, 2020
@escopecz escopecz moved this from Needs code review and/or test to Done in Mautic 3 Feb 17, 2020
@escopecz escopecz deleted the export-error-fix branch February 17, 2020 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs
Projects
No open projects
Mautic 3
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants