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

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

Open
ionutwho opened this issue Aug 15, 2023 · 2 comments

Comments

@ionutwho
Copy link

ionutwho commented Aug 15, 2023

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')
        ];
    }
}
@bizley
Copy link
Member

bizley commented Aug 16, 2023

Enums are not supported yet but we will be happy to provide it. Do you have a time to prepare the PR maybe?

@ionutwho
Copy link
Author

Sure, i have just created the PR: #19928

Could i use this fix for 2.0.48.1 or do i have to wait for the next release? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants