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

The Archive Base Latest Questions

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

I am trying to create a simple MVC my personal use and I could

  • 0

I am trying to create a simple MVC my personal use and I could really use an answer to this simple question

class theParent extends grandParent{

    protected $hello = "Hello World";

    public function __construct() {
        parent::__construct();
    }

    public function route_to($where) {
        call_user_func(array("Child", $where), $this);
    }
}

class Child extends theParent {

    public function  __construct() {
        parent::__construct();
    }

    public function index($var) {
        echo $this->hello;
    }

}

$x = new theParent();
$x->route_to('index');

Now Child::index() this throws a fatal error: Using $this when not in object context but if I were to use echo $var->hello, it works just fine.

I know I can use $var to access all properties in the parent, but I would rather use $this.

  • 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-23T03:26:31+00:00Added an answer on May 23, 2026 at 3:26 am

    You don’t have an instance of Child to call a non-static method upon when you’re doing $x->route_to('index'); The way you’re calling the method, without having made an instance first, is implied static.

    There are two ways to correct it. Either make the Child class’s methods static:

    class Child extends theParent {
    
        public function  __construct() {
            parent::__construct();
        }
    
        static public function index($var) {
            echo self::$hello;
        }
    
    }
    

    …or make an instance of the child class for the parent to use:

       class theParent extends grandParent{
    
            protected $hello = "Hello World";
            private $child = false
    
            public function __construct() {
                parent::__construct();
            }
    
            public function route_to($where) {
                if ($this->child == false)
                  $this->child = new Child();
                call_user_func(array($this->child, $where), $this);
            }
        }
    

    Of course, both of these samples are rather generic and useless, but you see the concept at hand.

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

Sidebar

Related Questions

I'm playing with the ASP.NET MVC Framework, trying to create a simple site. My
I'm new to postgreSQL and I have a simple question: I'm trying to create
I am trying to create a simple dialog in MFC using Visual C++. My
I am trying to create a simple page that enters data in to a
I'm trying to create a simple BaSH-like grammar on ANTLRv3 but haven't been able
I'm trying to create a simple toggling sidebar using jquery, where it expands and
I am trying to create a rather simple effect on a set of images.
Im using Eclipse 3.4, EclipseMe 1.7.9. Im trying to deploy/create package a simple project
I'm trying to come up with a simple and efficient way to create a
I'm trying to create a simple spring based webservice that supports a post with

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.