Skip to content

Conversation

@wutsch0
Copy link

@wutsch0 wutsch0 commented May 6, 2019

no QA needed

if (is_array($value) && 1 === count($value)) {
$value = reset($value);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please shortly explain why is it needed and why is it php7 related?
Is (string)$array works differently in php7?
How it supposed to work in $value is an array but with more them 1 element?

Copy link
Author

Choose a reason for hiding this comment

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

It is not really php7 related, did popup before as well. The Choice validator casts choice values to strings before checking if they exist in $choices array, but the values can be arrays as well (here a sfWidgetFormSelectRadio widget). To prevent the warning/notification the value array should be replaced by its only item

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is a misuse of the validator - because it has other clean function for the case when multiple choice is enabled

  protected function doClean($value)
  {
    $choices = $this->getChoices();

    if ($this->getOption('multiple'))
    {
      $value = $this->cleanMultiple($value, $choices);
    }
    else
    {
      if (!self::inChoices($value, $choices))
      {
        throw new sfValidatorError($this, 'invalid', array('value' => $value));
      }
    }

    return $value;
  }

So somewhere "multiple" widget is used with choice validator where "multiple" option is not enabled. We rather fix that one, than making this change.

@wutsch0 wutsch0 closed this May 24, 2019
@wutsch0 wutsch0 deleted the SENTRY-514224-fix-choice-validator branch May 24, 2019 15:40
MiguelAlcaino pushed a commit that referenced this pull request Aug 18, 2023
ValueError: fread(): Argument #2 ($length) must be greater than 0

TypeError: count(): Argument #1 ($value) must be of type Countable|array Foo Given
Use Symfony Polyfill symfony/polyfill@d330c00

TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given
Do not use Symfony pollyfill, is_array is enought
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

Successfully merging this pull request may close these issues.

3 participants