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

PHP 7.2+ compatibility issue line 302 count() parameter must be an array #60

Open
cylkee opened this issue Oct 17, 2019 · 3 comments
Open

Comments

@cylkee
Copy link

cylkee commented Oct 17, 2019

  • Sym: 2.7.10
  • PHP: 7.3
  • Search Index: 0.9.5

Steps to reproduce:

Visit /symphony/extension/search_index/indexes/ via the Search Index > Indexes menu item.

From php.net: Since PHP 7.2.0: count() will now yield a warning on invalid countable types passed to the array_or_countable parameter.

If I roll back to PHP 7.1 all is well.

Symphony Warning: count(): Parameter must be an array or an object that implements Countable

An error occurred in /path-redacted/extensions/search_index/content/content.indexes.php around line 302

    297  
    298  if ($index) {
    299      $col_name->appendChild(Widget::Input("items[{$section->get('id')}]", null, 'checkbox'));
    300  }
    301  
    302  if ($index && isset($index['fields']) && count($index['fields'] > 0)) {
    303      $section_fields = $section->fetchFields();
    304      $fields = $this->_indexes[$section->get('id')]['fields'];
    305      $fields_list = '';
    306      foreach($section_fields as $section_field) { 

Backtrace

    [/path-redacted/extensions/search_index/content/content.indexes.php:302]
        GenericErrorHandler::handler();
    [/path-redacted/symphony/lib/toolkit/class.administrationpage.php:801]
        contentExtensionSearch_IndexIndexes->__viewIndex();
    [/path-redacted/symphony/lib/toolkit/class.administrationpage.php:751]
        AdministrationPage->__switchboard();
    [/path-redacted/symphony/lib/toolkit/class.administrationpage.php:496]
        AdministrationPage->view();
    [/path-redacted/extensions/search_index/content/content.indexes.php:36]
        AdministrationPage->build();
    [/path-redacted/symphony/lib/core/class.administration.php:205]
        contentExtensionSearch_IndexIndexes->build();
    [/path-redacted/symphony/lib/core/class.administration.php:483]
        Administration->__buildPage();
    [/path-redacted/symphony/lib/boot/func.utilities.php:253]
        Administration->display();
    [/path-redacted/symphony/lib/boot/func.utilities.php:235]
        symphony_launcher();
    [/path-redacted/index.php:19]
        symphony();

Database Query Log

    [0.0001] SET character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8';
    [0.0000] SET CHARACTER SET 'utf8';
    [0.0001] SET time_zone = '+01:00';
    [0.0005] SELECT SQL_CACHE t1.name, t2.page, t2.delegate, t2.callback FROM `sym_extensions` as t1 INNER JOIN `sym_extensions_delegates` as t2 ON t1.id = t2.extension_id WHERE t1.status = 'enabled' ORDER BY t2.delegate, t1.name;
    [0.0002] SELECT SQL_CACHE `session_data` FROM `sym_sessions` WHERE `session` = 'session-token-redacted' LIMIT 1;
    [0.0002] SELECT SQL_CACHE a.* FROM `sym_authors` AS `a` WHERE `username` = 'user-redacted' ORDER BY a.id ASC LIMIT 1;
    [0.0002] UPDATE sym_authors SET `last_seen` = 'time-redacted' WHERE `id` = 1;
    [0.0003] SELECT SQL_CACHE `s`.* FROM `sym_sections` AS `s` ORDER BY `s`.`name` ASC;
    [0.0002] SELECT SQL_CACHE `name` FROM `sym_extensions` WHERE `status` = 'enabled';
    [0.0001] SELECT SQL_CACHE * FROM `sym_extensions`;
    [0.0003] SELECT SQL_CACHE `s`.* FROM `sym_sections` AS `s` ORDER BY `s`.`sortorder` asc; 
@jude86-7
Copy link

jude86-7 commented Jan 6, 2020

@cylkee I used is_countable instead of count, which appears to have removed the error...

if ($index && isset($index['fields']) && is_countable($index['fields'])) {

I haven't fully tested yet but thought it might help you out.

@cylkee
Copy link
Author

cylkee commented Jan 6, 2020

@jude86-7 Thanks.

Looks like is_countable was added in PHP 7.3, so another solution would be needed to cover PHP 7.2.

cylkee added a commit to cylkee/search_index that referenced this issue Feb 28, 2020
Put `> 0` outside `count()` - see symphonists#60 for more info.
@cylkee
Copy link
Author

cylkee commented Feb 28, 2020

Upon revisiting this, I think I figured out what was wrong > 0 should be outside count(). Retested on my installation, switching to PHP 7.3.15, and all good. Submitted PR #62

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