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

fix Getting unknown property #20173

Closed
wants to merge 1 commit into from
Closed

Conversation

sichkarev
Copy link

Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Fixed issues

@machour
Copy link
Member

machour commented May 29, 2024

This doesn't look right to me. If you're misconfigured the behavior, the application should throw, and you should fix your code, instead of silently getting a null.

What's your use-case here?

@sichkarev
Copy link
Author

sichkarev commented May 29, 2024

What's your use-case here?

In our project, we use ActiveRecords in migrations. Data are received from database and after receiving, properties of model will be casted to any types.
('typecastAfterFind' => true)

After switching to PHP 8.3, this behavior began to generate an exception, because The model describes properties that do not yet exist (they will be created in one of next migrations).

public function behaviors(): array
    {
        return ArrayHelper::merge(
            parent::behaviors(),
            [
                'typecast' => [
                    'class' => AttributeTypecastBehavior::class,
                    'attributeTypes' => [
                        'attribute_example' => AttributeTypecastBehavior::TYPE_INTEGER,
                    ],
                    'typecastBeforeSave' => true,
                    'typecastAfterFind' => true,
                ],
            ]
        );
    }

Example code in first migration:

$countries = Country::find()->all();

Example code in second migration:

        $this->addColumn('countries', 'attribute_example', $this->integer());

@sichkarev
Copy link
Author

instead of silently getting a null.

Even before my commit, the class was returning null

I just added a simple check for suppress the exception

@sichkarev sichkarev closed this May 29, 2024
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.

2 participants