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 8640743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:21:13+00:00 2026-06-12T11:21:13+00:00

I have seen number of frameworks implement DI in php. However, since all objects

  • 0

I have seen number of frameworks implement DI in php. However, since all objects in php get created and destroyed during the lifetime of a single request, I wonder how this affects performance.

Generally, you will define a number of objects inside a DI container. In php, even if a Controller does not need most of these objects, they will still be instantiated.
Also, if you declare your DI dependencies in a php file, you will load all referenced scripts. Without DI, you load only what you need.

I have seen some frameworks permit lazy DI, so this should help with unneeded instantiation. Maybe segmenting DI is also a way to address the first issue.
So, will DI adversely affect my php application performance and how should I go about implement DI in php so it does not happen?

  • 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-12T11:21:14+00:00Added an answer on June 12, 2026 at 11:21 am

    You have to identify if there is a problem, and then what is the problem.

    • Do you have dependencies that take a lot of resources and time to build?

    You can use lazy-injection, something like:

    class Class1 {
        /**
         * @Inject(lazy=true)
         * @var Class2
         */
        private $class2;
    
        public function doSomething() {
            // The dependency is loaded NOW
            return $this->class2->getSomethingElse();
        }
    

    (example from PHP-DI)

    • Do you have too many dependencies in your classes?

    You have to ask yourself if dependency injection is really the problem. If you where creating new instances (or using Singletons) instead of using DI, would the problem go away? (I don’t think so)

    IMO performance considerations should come with a clear identification that DI is the problem. There are so many parts that can go wrong in an application.

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

Sidebar

Related Questions

I have seen a number of C# roles that specifically require WinForms experience. However
I have seen this post which explains how to get the number of milliseconds
I have seen a number of hacks to try to get the bcp utility
I have seen that a prime number implementation of the GetHashCode function is being
On a number of machines (with Asp.net 1 and 2) we have seen the
In looking through samples I have seen a number of examples where it is
I have seen a number of Javascript examples to throw on top of an
I have seen a number of questions in which the term 'true p2p' is
So I have seen a number of references and links from a year +/-
I've recently been looking at SSL certificates and have seen a number of vendors

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.