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

  • Home
  • SEARCH
  • 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 6166545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:21:23+00:00 2026-05-23T22:21:23+00:00

I am trying to setup my php (Zend Framework) project through injection dependence .

  • 0

I am trying to setup my php (Zend Framework) project through injection dependence. So far when I instanciated a model, I would pass the table and the view (database view) to my model like that:

$table = new My_Table();
$view = new My_View();
$model = new My_Model($table, $view);

All my models extends a Same class that take care of the construction, message handling and getters for forms to interact with the model.

Now I have to inject a model into a model and I was looking for a passive static way of doing this. In my model’s parent class I have added a static method inject which is called in the application bootstrap. I pass two string in the form of key => value where the key is the name of the variable that have to be created in the model and the value is the string that represents the class to be instanciated.

My_Model::inject('dependentModel', 'My_Other_Model')

The issue arise when I try to use the key as a new member variable through the following code :

protected function _initDependency()
{
    $this->_table = null;

    foreach (self::$_staticDependency as $key => $dependency) {
        $varName = '_' . $key;
        $this->{$$varName} = new $dependency();
    }
}

I get the following message

Notice: Undefined variable: _dependentModel

What would be the best way to achieve that, knowing that I want to create my models ignorants of their dependencies?

  • 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-23T22:21:24+00:00Added an answer on May 23, 2026 at 10:21 pm

    Use arrays

    class Foo {
      private $_data = array();
    
    
      protected function _initDependency()
      {
        $this->_table = null;
    
        foreach (self::$_staticDependency as $key => $dependency) {
          $varName = '_' . $key;
          $this->_data[$varName] = new $dependency();
        }
      }
    }
    

    (As a side effect this also removes the variable-variables)

    You can use __get(), __set(), __isset() and __unset() to simulate the property-behaviour.

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

Sidebar

Related Questions

Trying to get a simple PHP/Zend Framework setup to create a SQLite databse and
I am trying to setup the Zend Framework on a windows machine and I
I have a website running using Zend Framework and am trying to setup Zend
I am trying to add some administration scripts to a Zend Framework project, that
I'm trying to setup an Apache/PHP/Postgresql server locally on my machine. I'm using Windows
I'm trying to setup CruiseControl.net at the moment. So far it works nice, but
I am trying to setup tracd for the project I am currently working on.
With the Zend Framework, I am trying to build routes for a REST api
I'm using some Zend libraries outside of the Zend Framework in a small project.
I'm trying to setup a simple slide show using ContentFlow javascript ( http://www.jacksasylum.eu/ContentFlow/index.php ),

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.