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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:53:57+00:00 2026-06-04T12:53:57+00:00

I have the following: class A { public function getDependencies() { //returns A.default.css, A.default.js,

  • 0

I have the following:

class A
{
    public function getDependencies()
    {
        //returns A.default.css, A.default.js, A.tablet.css, A.tablet.js, etc,
        //depending on what files exist and what the user's device is.
    }
}

In class B, which extends A, if I call getDependencies I will get things like: B.default.css, B.default.js and so on.

What I want to do now is include the results of A as well, without having to override getDependencies() in B. In fact, I’m not even sure if overriding would work, at all. Is this possible?

This is for dynamic CSS/JS loading for templates, and eventually compilation for production as well.

EDIT= I should point out that what getDependencies returns is dynamically generated, and not a set of stored values.

EDIT2= The idea I have is that just inheriting from A will provide the behavior. I probably need some kind of recursion that goes through the hierarchy tree, starting from B, to B’s parent, and all the way up to A, without any method overriding happening along the way.

  • 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-04T12:53:58+00:00Added an answer on June 4, 2026 at 12:53 pm

    Use parent::getDependencies(), e.g.:

    class B
    {
      public function getDependencies()
      {
        $deps = array('B.style.js' 'B.default.js', 'B.tables.js' /*, ... */);
        // merge the dependencies of A and B
        return array_merge($deps, parent::getDependencies());
      }
    }
    

    You can also try this code which uses ReflectionClass in order to iterate over all parents:

    <?php
    
    class A
    {
      protected static $deps = array('A.default.js', 'A.tablet.js');
      public function getDependencies($class)
      {
        $deps = array();
    
        $parent = new ReflectionClass($this);
    
        do 
        {
          // ReflectionClass::getStaticPropertyValue() always throws ReflectionException with
          // message "Class [class] does not have a property named deps"
          // So I'm using ReflectionClass::getStaticProperties()
    
          $staticProps = $parent->getStaticProperties();
          $deps = array_merge($deps, $staticProps['deps']);
        }
        while ($parent=$parent->getParentClass());
    
        return $deps;
      }
    }
    class B extends A
    {
      protected static $deps = array('B.default.js');
    }
    
    class C extends B
    {
      protected static $deps = array('C.default.js');
    }
    
    $obj = new C();
    var_dump( $obj->getDependencies($obj) );
    

    On Ideone.com

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

Sidebar

Related Questions

I have following php class class User implements IUser { public function __construct($i_objParent =
If I have the following registry class: Class registry { private $_vars; public function
I have code as following: Public Class xxxSvcHostFactory Inherits ServiceHostFactory Protected Overrides Function CreateServiceHost(ByVal
this is my first question I Have following class class ProDetection { public function
I have following class for a form: class Application_Form_ContactForm extends Zend_Form { public function
Providing that I have the following on: TeamGamesDao Class: public function listOfTeams() { $select
Say I have the following: class C { private $f; public function __construct($f) {
I have the following class public class classB : classA which contains function dostuff
I have the following model : class Model extends BaseModel { public function save($conn
I have the following class structure: class Parent { public function process($action) { //

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.