You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there, I found a bug that exists in 3.4, 4.1 and master branches.
I'll submit a PR soon.
What's happening:
That's the priorities issue: findAdderAndRemover('User', 'email') is called earlier than $this->isMethodAccessible('User', 'setEmail', 1)
The reproducer:
$user = new UserWithSingularAndPluralProps();
$accessor = PropertyAccess::createPropertyAccessor();
if ($accessor->isWritable($user, 'email')) {
$accessor->setValue($user, 'email', 'test@email.com');
}
Here is User entity that has email and emails fields:
/**
* Notice we don't have setter for emails
* because we count on adder/remover
*/
class UserWithSingularAndPluralProps
{
/** @var string|null */
private $email;
/** @var array */
private $emails = [];
/**
* @return null|string
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @param null|string $email
*/
public function setEmail(?string $email): void
{
$this->email = $email;
}
/**
* @return array
*/
public function getEmails(): array
{
return $this->emails;
}
/**
* @param string $email
*/
public function addEmail(string $email): void
{
$this->emails[] = $email;
}
/**
* @param string $email
*/
public function removeEmail(string $email): void
{
$this->emails = array_diff($this->emails, [$email]);
}
}
Expected result: the value is assigned to user.email.
Actual error: Invalid argument supplied for foreach() in symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php line 576
The text was updated successfully, but these errors were encountered:
…y using setter while plural adder/remover exist (karser)
This PR was merged into the 3.4 branch.
Discussion
----------
[PropertyAccessor] Fix unable to write to singular property using setter while plural adder/remover exist
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #28961
| License | MIT
Please take a look at the tests I added - they describe the issue. It has to do with the priorities: `findAdderAndRemover('User', 'email')` is called earlier than `$this->isMethodAccessible('User', 'setEmail', 1)`
Commits
-------
8238f16 [PropertyAccessor] Fix unable to write to singular property using setter while plural adder/remover exist
Hi there, I found a bug that exists in 3.4, 4.1 and master branches.
I'll submit a PR soon.
What's happening:
That's the priorities issue:
findAdderAndRemover('User', 'email')
is called earlier than$this->isMethodAccessible('User', 'setEmail', 1)
The reproducer:
Here is User entity that has
email
andemails
fields:Expected result: the value is assigned to user.email.
Actual error:
Invalid argument supplied for foreach() in symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php line 576
The text was updated successfully, but these errors were encountered: