Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:58:36+00:00 2026-06-17T19:58:36+00:00

So I know the basics of Dependency Injection. I should pass in my dependencies

  • 0

So I know the basics of Dependency Injection. I should pass in my dependencies as method parameters instead of instantiating the objects themselves inside the method.

I was wondering if this also applies to classes that come with PHP, such as DateTime objects or ReflectionClass objects?

For example one of the methods of a class I’m working on needs to know about the properties of a object that is passed in. I wanted to use a ReflectionClass to accomplish the task, but I thought it seemed unnecessary to have to pass a ReflectionClass object as a parameter if the class will always be accessible and relatively unchanged (Unless ReflectionClass changes with newer PHP versions).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:58:38+00:00Added an answer on June 17, 2026 at 7:58 pm

    It depends on the design requirements of your application.

    If you know that your application requires a DateTime for a specific method to function, then pass in a DateTime. If you require custom functionality around a DateTime, then consider sub-classing DateTime and send that.

    If you decide to use PHP’s type hints in your method signature, consider using an interface instead, so that any object sent will fulfill that contract with the receiving class. This approach can also help insulate your application against incompatible changes in PHP in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I know the basics about when indexing should be used and the pros
I've been reading about dependency injection , and I'm getting the basics. Most of
I know basics of UML and java's OO interpretations using class diagrams. But after
I have a problem with operators. Generally I know basics of using operators. But
i know the basics of recursion but in the given code i m facing
I know how a relational database stores data. I know the basics of indexeddb
I am new to c++ programming and know the basics of c++. I am
I understand the basics of networking such as Lan and stuff. I know what
I want to know about Virtualization in detail. But start from basics, like what
I am trying to implement Dependency Injection to make my app tester friendly. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.