Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[PropertyAccess] Reset object property to either null or uninitialized state#44880

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
filiplikavcan wants to merge2 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
frombratiask:6.1

Conversation

filiplikavcan
Copy link
Contributor

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
Tickets#44686
LicenseMIT
Doc PR

Description

I propose extending Property Accessor with an optional feature that could enable checking whether object setter has a non-nullable parameter and would call unset($object->parameter) instead of $object->setParameter($value) if $value is null and $object implements __unset() method.

Motivation

Form component could use this feature and reset non-nullable properties to uninitialized state when null value is submitted for a non-nullable property. Currently when a NotNull constraint is set on a property it is only evaluated for a new object (with uninitialized properties). Once the value for the property is set (for example through Doctrine hydration) and a user submits an empty/null value the constraint is never evaluated because execution fails on Property Accessor trying to call setter with non-nullable parameter.

Example

class User{privatestring$name;publicfunctionsetName(string$name)    {$this->name =$name;    }publicfunction__unset($property)    {        unset($this->$property);    }}$user =newUser;$propertyAccessor->setValue($user,'name','John');// $user->setName('John') is called$propertyAccessor->setValue($user,'name',null);// Fatal error: User::setName(): Argument #1 ($name) must be of type string, null given$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()    ->enableMagicUnset()    ->getPropertyAccessor();$propertyAccessor->setValue($user,'name',null);// unset($user->name) is called

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

It looks like you unchecked the "Allow edits from maintainer" box. That is fine, but please note that if you have multiple commits, you'll need to squash your commits into one before this can be merged. Or, you can check the "Allow edits from maintainers" box and the maintainer can squash for you.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

I think@HeahDude has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@carsonbotcarsonbot changed the titleReset object property to either null or uninitialized state[PropertyAccess] Reset object property to either null or uninitialized stateJan 4, 2022
@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.2,6.3Nov 5, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

6 participants
@filiplikavcan@carsonbot@fabpot@nicolas-grekas@Nyholm@xabbuh

[8]ページ先頭

©2009-2025 Movatter.jp