8000 [PropertyAccess] Fix TypeError discard by dunglas · Pull Request #23333 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyAccess] Fix TypeError discard #23333

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

Merged
merged 1 commit into from
Jul 3, 2017

Conversation

dunglas
Copy link
Member
@dunglas dunglas commented Jun 30, 2017
Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Given the following code:

class Bar
{
    private $foos = [];

    public function getFoos(): array
    {
        return 'It doesn\'t respect the return type';
    }

    public function addFoo(Foo $foo)
    {
        // ...
    }

    public function removeFoo(Foo $dateTime)
    {
        // ...
    }
}

$object = new Bar();
$this->propertyAccessor->setValue($object, 'foos', array(new \DateTime()));

The PropertyAccessor will crash ([Symfony\Component\Debug\Exception\ContextErrorException] Notice: Undefined offset: 0) instead of displaying the (valid) PHP error.

This PR fixes the issue.

@dunglas dunglas force-pushed the fix_property_access_discard_error branch from beeab0d to e0c5040 Compare June 30, 2017 09:25
@fabpot
Copy link
Member
fabpot commented Jul 3, 2017

Thank you @dunglas.

@fabpot fabpot merged commit e0c5040 into symfony:2.7 Jul 3, 2017
fabpot added a commit that referenced this pull request Jul 3, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

[PropertyAccess] Fix TypeError discard

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? |no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Given the following code:

```php
class Bar
{
    private $foos = [];

    public function getFoos(): array
    {
        return 'It doesn\'t respect the return type';
    }

    public function addFoo(Foo $foo)
    {
        // ...
    }

    public function removeFoo(Foo $dateTime)
    {
        // ...
    }
}

$object = new Bar();
$this->propertyAccessor->setValue($object, 'foos', array(new \DateTime()));
```

The `PropertyAccessor` will  crash (`[Symfony\Component\Debug\Exception\ContextErrorException]  Notice: Undefined offset: 0`) instead of displaying the (valid) PHP error.

This PR fixes the issue.

Commits
-------

e0c5040 [PropertyAccess] Fix TypeError discard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0