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

Parameter must be an array or an object that implements Countable - Suppliers Payments Preview #9074

Closed
torvista opened this issue Jul 8, 2018 · 2 comments

Comments

@torvista
Copy link
Contributor

torvista commented Jul 8, 2018

Bug

Error on pdf preview for Suppliers Payments

Environment

  • Version: 9 alpha/develop
  • OS: Windows 10
  • Web server: xampp 7.2.6
  • PHP: 7.2.6
  • Database: 10.1.33-MariaDB
  • URL(s): ...../dolibarr-develop/htdocs/admin/supplier_payment.php

Expected and actual behavior

No preview, only error:

Warning: count(): Parameter must be an array or an object that implements Countable in ...\Dev\public_html\dolibarr-develop\htdocs\core\modules\supplier_payment\doc\pdf_standard.modules.php on line 213
Fatal error: Uncaught InvalidArgumentException: Parameter 1 $thirdparty is not a Societe nor Contact in ...\Dev\public_html\dolibarr-develop\htdocs\core\lib\pdf.lib.php:333
Stack trace:
#0 ...\Dev\public_html\dolibarr-develop\htdocs\core\modules\supplier_payment\doc\pdf_standard.modules.php(713): pdfBuildThirdpartyName(NULL, Object(Translate))
#1 ...\Dev\public_html\dolibarr-develop\htdocs\core\modules\supplier_payment\doc\pdf_standard.modules.php(253): pdf_standard->_pagehead(Object(TCPDI), Object(PaiementFourn), 1, Object(Translate))
#2 ...\Dev\public_html\dolibarr-develop\htdocs\admin\supplier_payment.php(129): pdf_standard->write_file(Object(PaiementFourn), Object(Translate))
#3 {main} thrown in ...\Dev\public_html\dolibarr-develop\htdocs\core\lib\pdf.lib.php on line 333

Steps to reproduce the behavior

New install: only modules enabled, no customers or products.
Modules/Application setup->Suppliers->Suppliers Payments
Payment Documents Models
Click on Preview link to trigger error.

Note that the Preview link on other modules works as expected.

@ttobsen
Copy link

ttobsen commented Aug 8, 2018

Since PHP 7.2, the count() function breaks compatibility to previous PHP versions. See http://php.net/manual/en/migration72.incompatible.php#migration72.incompatible.warn-on-non-countable-types

PHP now throws a warning when counting non countable types (the return values are still the same to prevent at least functional compatibility). I see two possible solutions:

1.) The countable interface needs to be implemented to all classes, see http://php.net/manual/en/class.countable.php

But there are also some cases where scalar types or null is tried to count. This case needs to be fetched before the count operation wil be applied. (See case 2.)

2.) Check before every count() operation if the operand is countable. With the coming PHP 7.3 version, there will a function be implemented, which helps to solve this problem, see https://wiki.php.net/rfc/is-countable

For in-depth information why PHP 7.2 has a change in the count() method, see https://wiki.php.net/rfc/counting_non_countables

@hregis
Copy link
Contributor

hregis commented Aug 8, 2018

@torvista @ttobsen @eldy
I valid ! WHY replace "if empty" with "if count > 0" under certain circumstances?

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

3 participants