Coder Social home page Coder Social logo

Comments (13)

n0rbyt3 avatar n0rbyt3 commented on June 3, 2024 1

There is an updated check for non-initialized properties which causes the issue:

if (!isset($object->$name) && !\array_key_exists($name, (array) $object)) {
try {
$r = new \ReflectionProperty($class, $name);
if ($r->isPublic() && !$r->hasType()) {
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $class, $name));
}
} catch (\ReflectionException $e) {
if (!$ignoreInvalidProperty) {
throw new NoSuchPropertyException(sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
}
}
}

Your magic __get() method can handle uninitialized properties by returning null. Adding this __isset() method resolves the issue:

public function __isset(string $name): bool
{
  return true;
}

from symfony.

boonkerz avatar boonkerz commented on June 3, 2024 1

yea that works but this is not obvious.
the docs does not say anything about this new behaviour
https://symfony.com/doc/current/components/property_access.html#magic-get-method
and its differ from the previous version.

from symfony.

k0d3r1s avatar k0d3r1s commented on June 3, 2024 1

i will add this here:
property-access 6.4.6 and 6.4.7 breaks doctrine migrations diff, going back to 6.4.4 fixes the issue

from symfony.

aesislabs avatar aesislabs commented on June 3, 2024 1

Same problem here, it break my applications

from symfony.

xabbuh avatar xabbuh commented on June 3, 2024

Looks like your class is missing the implementation of the __isset() method:

public function __isset(string $name): bool
{
    return null !== ($this->tests[$name] ?? null);
}

from symfony.

boonkerz avatar boonkerz commented on June 3, 2024
class test
{

    private array $tests = [];

    public function __get(string $name): mixed
    {
        return $this->tests[$name]?? null;
    }

    public function __set(string $name, mixed $value): void
    {
        $this->tests[$name] = $value;
    }

    public function __isset(string $name): bool
    {
        return null !== ($this->tests[$name]?? null);
    }
}


$test = new test();
$propertyAccessor = new PropertyAccessor();
var_dump($propertyAccessor->getValue($test, 'Wouter'));

this does not help to fix the behaviour.

returns the same error.

from symfony.

boonkerz avatar boonkerz commented on June 3, 2024

Here is the Code

https://phpsandbox.io/n/propertyaccess-fipnm

from symfony.

bastien-effetb avatar bastien-effetb commented on June 3, 2024

Same problem here

from symfony.

n0rbyt3 avatar n0rbyt3 commented on June 3, 2024

Indeed, it's just a workaround.

Friendly ping @nicolas-grekas who changed the implementation in commit 9610a7c. An __isset() implementation has been added to the TestClassMagicGet fixture which is a BC break.

I don't see any reason why this additional check exists. IMO, it's part of the PropertyTypeExtractorInterface to detect if the property is accessible. The ReflectionExtractor inside the PropertyInfo component does all the reflection logic so there should be no need to reflect the property again - even if another PropertyTypeExtractorInterface implementation is used. Otherwise PropertyReadInfo should be extended to return more details for the PropertyAccessor.

from symfony.

derrabus avatar derrabus commented on June 3, 2024

@k0d3r1s Please open a new issue with a detailed reproducer.

from symfony.

nicolas-grekas avatar nicolas-grekas commented on June 3, 2024

That's because you're missing an implementation for __isset. While property access was tolerant to this, this breaks the behavior of objects with the php engine.

from symfony.

netsuo avatar netsuo commented on June 3, 2024

I have no problem with that, but maybe it needs some doc update

from symfony.

nicolas-grekas avatar nicolas-grekas commented on June 3, 2024

Maybe a note in the UPGRADE-6.4.md file? Up for a PR?

from symfony.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.