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]: Form with field that is not part of the Model raised deprecated warning on bind() #16567

Closed
noone-silent opened this issue Apr 9, 2024 · 2 comments
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Comments

@noone-silent
Copy link
Contributor

Describe the bug
If you have a form with a field, that is not part of the model you bind the form to, the form will dynamically add the field to the model, which raises a deprecated warning.

Deprecated: Creation of dynamic property Model::$attribute is deprecated

To Reproduce

class TestModel extends \Phalcon\Mvc\Model
{
  public ?string $inModel = null;
}

class TestForm extends \Phalcon\Forms\Form
{
  public function initialize(TestModel $entity): void
  {
    $this->add(new \Phalcon\Forms\Element\Check('notInModel', ['value' => 1]));
    $this->add(new \Phalcon\Forms\Element\Text('inModel', ['value' => $entity->inModel]));
  }
}

$testModel = new TestModel();
$testForm = new TestForm($testModel);

// Result: Deprecated: Creation of dynamic property TestModel::$notInModel is deprecated
$testForm->bind(['inModel' => 'test 123', 'notInModel' => '1'], $testModel);

Expected behavior
Form should only fill fields that are part of the entity using model metadata only. If there is not metadata then use reflection.

Screenshots

Details

  • Phalcon version: 5.6.2
  • PHP Version: 8.2
  • Operating System: debian
  • Installation type: installing via package manager
  • Zephir version (if any): none
  • Server: Nginx
  • Other related info (Database, table schema): -

Additional context

@noone-silent noone-silent added bug A bug report status: unverified Unverified labels Apr 9, 2024
@noone-silent
Copy link
Contributor Author

https://github.com/phalcon/cphalcon/blob/master/phalcon/Forms/Form.zep#L257

I think a property_exists($entity, $key) would help here.

There is also a better way to only allow public properties: https://www.php.net/manual/de/function.property-exists.php#129001

noone-silent added a commit to noone-silent/cphalcon that referenced this issue May 1, 2024
…ng properties on entities when bind is executed.

refactor: added new ini setting phalcon.form.strict_entity_property_check with default value of 0
noone-silent added a commit to noone-silent/cphalcon that referenced this issue May 1, 2024
niden added a commit that referenced this issue May 1, 2024
…roperty-check

[#16567] - Fix for Form::bind deprecated warnings.
@niden niden added status: medium Medium 5.0 The issues we want to solve in the 5.0 release and removed status: unverified Unverified labels May 1, 2024
@niden
Copy link
Member

niden commented May 1, 2024

Resolved in #16575

Thank you again @noone-silent

@niden niden closed this as completed May 1, 2024
@niden niden added this to Phalcon v5 May 1, 2024
@niden niden moved this to In Progress in Phalcon v5 May 1, 2024
@niden niden moved this from In Progress to Implemented in Phalcon v5 May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Status: Implemented
Development

No branches or pull requests

2 participants