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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:33:31+00:00 2026-05-26T18:33:31+00:00

With a PHP MVC project, I have a few model classes that load data

  • 0

With a PHP MVC project, I have a few model classes that load data from a RESTful web service, which requires an API key. I’d like to store the necessary API key in the central config file of my application.

To get that API key to my class, which method would be considered best?

  1. Put the value in $GLOBALS, so it can be accessed directly within the model classes which utilize it.
  2. Pass the value to the class upon instantiation.

Method #2 seems best for OOP and code reuse, but method #1 is very convenient. I typically go with method #2, but I want to know if method #1 is generally considered to be an acceptable use of $GLOBALS, even in an OOP MVC environment.

  • 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-05-26T18:33:32+00:00Added an answer on May 26, 2026 at 6:33 pm

    Symfony 1.4 uses an sfConfig::get(‘my_value’), which is like your first option, only wrapped in an object.

    Symfony 2 uses dependency injection to reduce coupling, which is like your second option. Make sure you check out this link for a good explanation on dependency injection.

    However, reducing coupling increases complexity. So, it’s really a tradeoff. I think the main point is to be consistent in your application. Whichever method is used can be changed, so long as you’re consistent in its use.

    I would pick dependency injection. Not only is it easy to use if you use it all of the time, it’s much more likely to lead to reusable code. The slowest part of a computer is the developer, so I try to build high quality, reusable components, wherever possible. I should also note that using dependency injection makes it much, much easier to build unit tests, should you choose to increase the quality and consistency of your code by adding unit tests.

    Hope that helps…

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

Sidebar

Related Questions

I am creating a very large PHP MVC-based site that will have a large
I am working on a PHP project which makes extensive use of the MVC
I am working on a few PHP projects that use MVC frameworks, and while
I'm writing unit tests for a project (written in PHP, using PHPUnit) that have
I am currently developing a PHP MVC Framework for a personal project. While I
In a recent project, I built my own MVC framework in PHP. One of
I have a PHP MVC application using Zend Framework. As presented in the quickstart,
I have just started out with testing some php mvc framework In it, it
I came from PHP language(codeigniter), but now I learning ASP.Net MVC :) In PHP
I'm developing an MVC framework in PHP from scratch; mostly for the learning experience

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.