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

Typed property $value must not be accessed before initialization #288

Closed
Lumeriol opened this issue May 20, 2022 · 1 comment
Closed

Typed property $value must not be accessed before initialization #288

Lumeriol opened this issue May 20, 2022 · 1 comment

Comments

@Lumeriol
Copy link

Version: 4.0.x-dev

Bug Description

There is a rare occurence of not initialized value of form component.
I have this problem with used Contributte/FormMultiplier. When I use multiplier for component UploadControl, with created (or removed) new field, error is appeared (Typed property Nette\Forms\Controls\BaseControl::$value must not be accessed before initialization).

Problematic code is $obj->$name = $control->getValue() (Forms\Container.php:160), because value is unset. Other form components like TextInput, hidden fields, etc. are okay due having empty string or similar value, only Upload has this problem.
I tried to set various default values or disable required of this field, but error persist.

With Nette Forms 3.1 there is no problem because $value is not typed.

Note for the end :)
I know that FormMultiplier is not prepared for Nette 4 yet, but this maybe should not be problem of this library?

Steps To Reproduce

$multiplier = $form->addMultiplier('m_photo', function (Container $container, Form $form) {
            $container->addUpload('image')
                    ->addRule(Form::IMAGE, 'Fotogragie musí být JPEG, PNG, WebP nebo GIF.')
        }, 1, 10);

Possible Solution

Set default value to var $value in BaseControl

protected mixed $value = null;

@dg
Copy link
Member

dg commented Mar 8, 2023

thanks, fixes

@dg dg closed this as completed Mar 8, 2023
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