Skip to content
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

Dice calls name() method on ReflectionClass instance #132

Closed
jakubmikita opened this issue Aug 10, 2017 · 3 comments
Closed

Dice calls name() method on ReflectionClass instance #132

jakubmikita opened this issue Aug 10, 2017 · 3 comments

Comments

@jakubmikita
Copy link

Hi,

I'm trying to understand something. Here: https://github.com/Level-2/Dice/blob/master/Dice.php#L97 you are calling the name() method on ReflectionClass instance passing the list of callable arguments.

Please, could you give me a hint how is that possible? ReflectionClass doesn't have the name() method. Or is this part not used anymore and overlooked?

@maxwilms
Copy link
Contributor

Hello!

Yes, this code is still in use. For example BasicTest::testObjectGraphCreation() fails if you comment this line out.

Nevertheless it really looks confusing! But return new $class->name(...$params($args, $share)); does not call a method on the reflection class. Instead it gets the property name on the ReflectionClass and then calls the constructor on that class name.

This would be a more obvious version of this line:

$className = $class->name;
return new $className(...$params($args, $share));

Hope this helps.

@jakubmikita
Copy link
Author

Wow, that's really optimized! Thanks for the answer @maxwilms, I can see what's going on now.

@garrettw
Copy link

Feel free to close this issue if your question has been answered sufficiently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants