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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:05:00+00:00 2026-06-11T13:05:00+00:00

My problem is this (In PHP): I have three classes, Class cls1 { public

  • 0

My problem is this (In PHP):

I have three classes,

Class cls1 {
    public function myfunc() {

    }
}
Class cls2 {
    private $_obj1; //type of cls1
    ...
    public function getObj1() {
        return $_obj1;
    }
}

Class cls3 {
    ...
    public function getMyFunc() {
        $temp = new cls2();
        $temp->getObj1()->myfunc(); //THIS IS NOT WORKING.
        //PHP Throws an error like : Fatal error: Call to a member function getId() on a non-object in xyz.php on line 125.
    }
}

I cannot reach cls1’s function from cls3 through the way cls2.

How can I implement it?

NOTE: I wrote this basic code to show the problem. Do not consider about syntax errors.

  • 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-11T13:05:01+00:00Added an answer on June 11, 2026 at 1:05 pm

    Object1 hasn’t been instantiated yet.

    Class cls1 {
        public function myfunc() {
    
        }
    }
    Class cls2 {
        private $_obj1; //type of cls1
        ...
        public function getObj1() {
            if(!$this->$_obj1 instanceof cls1) {
                $this->_obj = new cls1();
            }
            return $_obj1;
        }
    }
    
    Class cls3 {
        ...
        public function getMyFunc() {
            $temp = new cls2();
            $temp->getObj1()->myfunc(); //THIS IS NOT WORKING.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this strange problem with the PHP function CTYPE_ALNUM if i do: PHP:
So I have this problem in PHP, I have a class called unit that
Dear everybody who can help, I have this PHP > MongoDB problem, I want
I have this problem getting my newly created php project on Netbeans work on
so I have this problem I have 3 files like 2.php <?php $variable =
I have this weird problem with setting up cookies with PHP. Everything worked fine
I have a conceptual problem to do with PHP classes and error handling.. Below
I have the following Regex used to match PHP Class, method and Function names
I have been using three classes. Two classes extends the third class db. But
I have an index.php with the following content: include_once('includes/auth.php'); include_once('classes/class.DatabaseQuery.php'); include_once('classes/class.Project.php'); include_once('classes/class.User.php'); $project =

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.