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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:08:28+00:00 2026-05-29T22:08:28+00:00

Here is the code layout outline all nicely laid out in 3 file and

  • 0

Here is the code layout outline all nicely laid out in 3 file and class’s

$aa = new className();
class className {
    /**
    * Constructor
    */
    function className() {
        $this->init_SubClass();
    }

    function init_SubClass() {
        require_once('sub_class.class.php');
        $sub_class = new sub_class();
    }
}

sub_class.class.php

   class sub_class {
    /**
    * Constructor
    */
    function sub_class() {
        $this->init_Sub_Sub_Class();
    }

    function init_Sub_Sub_Class() {
        require_once('Sub_Sub_Class.class.php');
        $Sub_Sub_Class = new Sub_Sub_Class();
    }
}

sub_sub_class.class.php

class Sub_Sub_Class {
    public function function_I_to_call() {
        echo ' show this text'
    }
}

How to a call function_I_to_call()

This was mybest guess so far

$aa->className->sub_class->function_I_to_call()

Not sure how to do this or if it can be done.

Many Thanks

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

    You are not assigning the newly created object to the instance. You need to use

    $this->sub_class = new Subclass;
    

    That will make them public properties and then you can use your

    $aa = new className;
    $aa->sub_class->function_I_to_call();
    

    However, the entire approach is completely flawed:

    • The constructor should be __construct. The old style constructor is a relic from PHP4 times and wont work with namespaced classes.
    • Assigning properties on the fly is considered bad practice, because it’s unobvious they exist when looking at the API. Declare them as members in the class.
    • Calls to require are unneeded when you use an Autoloader.
    • Use Dependency Injection to decouple your components. Makes them easier to unit-test as well.
    • If you need to assemble complex collaborator graphs, use a Factory or a Builder pattern instead.

    Alternate approach

    class Foo
    {
        protected $bar;
        public function __construct(Bar $bar)
        {
            $this->bar = $bar;
        }
        public function getBar()
        {
            return $this->bar;
        }
    }
    

    And then Bar

    class Bar
    {
        protected $baz;
        public function __construct(Baz $baz)
        {
            $this->baz = $baz;
        }
        public function getBaz()
        {
            return $this->baz;
        }
    }    
    

    And Baz:

    class Baz
    {
        public function fn()
        {
            return 'called';
        }
    }
    

    And then assemble it via:

    $foo = new Foo(new Bar(new Baz));
    

    Or move that code to a Factory:

    class FooFactory
    {
        public function create()
        {
            return new Foo(new Bar(new Baz));
        }
    }
    

    Finally, the Autoloader (simplified):

    spl_autoload_register(function($className) {
        $classMap = array(
            'Foo' => '/path/to/Foo.php',
            'Bar' => '/path/to/Bar.php',
            'Baz' => '/path/to/Baz.php',
        );
        require $classMap[$className];
    });
    

    And then you could call (demo)

    $fooFactory = new FooFactory;
    $foo = $fooFactory->create();
    echo $foo->getBar()->getBaz()->fn();
    

    But you shouldnt (unless it’s some sort of DSL), because that is violating Law of Demeter because you are digging too deep into the collaborators.

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

Sidebar

Related Questions

here is my mysql and php code layout: I have 3 tables tableA stores
Here's my layout code; <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent> <TextView android:text=@string/welcome
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
enter code here Hi All, I have a simple windows service application that connects
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have some code here (my activity class and some class, that extends WebViewClient)
So I'm toying with this code here, and the main objective is to update
I need showing a layout per some seconds, and here my code: public void
Here is my code... package com.bmc; public class Details extends Activity { public void

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.