Git Product home page Git Product logo

Comments (13)

dg avatar dg commented on August 23, 2024

Could you please report this as a PHP bug as well? That ReflectionParameter::getDefaultValue() crashes in this situation?

from di.

zeleznypa avatar zeleznypa commented on August 23, 2024

The old version with ReflectionParameter::getDefaultValue() works well in the same situation

from di.

dg avatar dg commented on August 23, 2024

So where's the problem?

from di.

zeleznypa avatar zeleznypa commented on August 23, 2024

The problem is in the new version, where the code $param->getDefaultValue()) is used and cause the "Error: Cannot access trait constant self::CONTROL_FLASH_MESSAGE directly"

from di.

dg avatar dg commented on August 23, 2024

So ReflectionParameter::getDefaultValue() isn't working so well, is it?

from di.

zeleznypa avatar zeleznypa commented on August 23, 2024

ReflectionParameter::getDefaultValue() works well
$param->getDefaultValue() cause the "Error: Cannot access trait constant self::CONTROL_FLASH_MESSAGE directly"

Nette\DI 3.2.0 works well
Nette\DI 3.2.2 cause the "Error: Cannot access trait constant self::CONTROL_FLASH_MESSAGE directly"

from di.

zeleznypa avatar zeleznypa commented on August 23, 2024

It is really strange, because when I tried to isolate the root cause in the 3v4l.org, it works also with the $param->getDefaultValue().

from di.

dg avatar dg commented on August 23, 2024

What is the difference between ReflectionParameter::getDefaultValue() and $param->getDefaultValue() ????

from di.

zeleznypa avatar zeleznypa commented on August 23, 2024

Sorry my fault :(

I was reporting and speaking about \Nette\Utils\Reflection::getParameterDefaultValue($param)

But you are speaking about \ReflectionParameter::getDefaultValue()

from di.

mabar avatar mabar commented on August 23, 2024

It is really strange, because when I tried to isolate the root cause in the 3v4l.org, it works also with the $param->getDefaultValue().

It happens only when $method is got from the trait reflection instead of the class reflection https://3v4l.org/s8ofg#v8.3.7
PHP (mostly) requires traits analysed in context of the class where the trait is used. And it makes sense in this case - constant could be defined by the class using the trait, not by the trait itself - https://3v4l.org/V4RNt#v8.3.7

(Interesting side-note: PHP allows to redefine constant value if it is defined by interface and overriden by a class or a trait, but constant value defined by a trait can't be redefined by a class, PHP would throw fatal error for that - https://3v4l.org/oYmEW#v8.3.7)

from di.

zeleznypa avatar zeleznypa commented on August 23, 2024

Great point @mabar. When I debug/try/catch/parse and then debug the situation that happening in my code, the $method when it crashed return the Trait as a result for ->getDeclaringClass().

The previous mechanism was safe, because it was parsing the constant value different way than current version, that try to access the trait constant directly.

So the \Nette\Utils\Reflection::getParameterDefaultValue() still have some place and should not be deprecated, because it can parse default value also for methods from trait?

from di.

dg avatar dg commented on August 23, 2024

And that brings us back to whether you could report this as a bug on PHP, because it should work.

from di.

zeleznypa avatar zeleznypa commented on August 23, 2024

@dg Im not sure with that.

A) I have never report a bug to PHP. Where should I do that?

B) I think, that it is not a bug of PHP.

You cant call PHP Trait::CONST, so you cant ask for Reflection on trait and getDefaultParameter, that (from my point of view) do the same.

When you call the reflection on the class that use the trait, it works.

What do you think?

from di.

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.