Skip to content

[?bug] BaseHtml line 1938 - v2.0.48.1 - Object of class "..." could not be converted to int - proposed workaround #19926

@ionutwho

Description

@ionutwho

Hello,

I'm getting the next error after updating from 2.0.44 to 2.0.48.1: Object of class "..." could not be converted to int

Please check BaseHtml:1938
https://github.com/yiisoft/yii2/blob/73902f0730454f499d1a8bb49382e5021943656e/framework/helpers/BaseHtml.php#L1938C44-L1938C44

var_dump($selection)

/project/vendor/yiisoft/yii2/helpers/BaseHtml.php:1938:
object("...")[315]
  protected 'value' => int 0
  protected string 'label' => string 'First' (length=7)

var_dump($key)

/project/vendor/yiisoft/yii2/helpers/BaseHtml.php:1939:int 0

Workaround:

$selected = is_object($selection) ?
                                $selection->value == $key : $selection == $key;

Should i keep this workaround or im getting the error due of my Enum:

/**
 * @method static self first()
 * @method static self second()
 * @method static self third()
 */
class BookSubject extends Enum
{
    /**
     * @codeCoverageIgnore
     */
    protected static function values(): array
    {
        return [
            'first' => 0,
            'second' => 1,
            'third' => 2
        ];
    }

    /**
     * @codeCoverageIgnore
     */
    protected static function labels(): array
    {
        return [
            'first' => \Yii::t('app', 'first'),
            'second' => \Yii::t('app', 'second'),
            'third' => \Yii::t('app', 'third')
        ];
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions