0

I've created a simple class Car which takes 2 arguments at its constructor, Wheels and SteeringWheel both of those arguments are another objects.

When I type App::make('Car'), as I recall, it should instantiate a Car object and do the dependency injection on it's own even without binding the Car class. However, when I do that, I get an error: ReflectionException: Class Car does not exist even tho I've used the Car namespace by doing: use Acme\Car at the top of the page.

However, if I provide to the make function the full "path" to the Car class, it works: App::make('\Acme\Car'); Any idea how I can make it work even if I type Car only?

1 Answer 1

2

The App::make() function doesn't use the includes at the top of the page, it creates a class from the string you provide. If you want to only use Car, remove the namespace Acme from the Car class.

Sign up to request clarification or add additional context in comments.

3 Comments

I see. Well that's quite understandable why I guess. Thanks for clarifying my suspicion
Just to clarify something, if I was to add the Car class as an alias, it would be okay if I typed Car only? And, how come if you use a model it works? all of the models are in the global namespace?
If you don't put namespace in the models yourself, they are default not in a namespace/in global namespace. If you add Car as an alias, it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.