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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:38:45+00:00 2026-06-07T22:38:45+00:00

I have protected function which creates a class object protected function x() { $obj

  • 0

I have protected function which creates a class object

protected function x() {
    $obj = new classx();
}

Now I need to access the methods of the class object from different functions (I don’t want to initialise again).

protected function y() {
    $objmethod = $obj->methodx();
}

How can i get it done?

Oh both the functions exist in the same class say ‘class z{}’

The error message is

Fatal error: Call to a member function get_verification() on a non-object in
  • 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-07T22:38:47+00:00Added an answer on June 7, 2026 at 10:38 pm

    Store $obj, the instance of classx in a property of ClassZ, probably as a private property. Initialize it in the ClassZ constructor or other initializer method and access it via $this->obj.

    class ClassZ {
      // Private property will hold the object
      private $obj;
    
        // Build the classx instance in the constructor
      public function __construct() {
        $this->obj = new ClassX();
      }
    
      // Access via $this->obj in other methods
      // Assumes already instantiated in the constructor
      protected function y() {
        $objmethod = $this->obj->methodx();
      }
    
      // If you don't want it instantiated in the constructor....
    
      // You can instantiate it in a different method than the constructor
      // if you otherwise ensure that that method is called before the one that uses it:
      protected function x() {
        // Instantiate
        $this->obj = new ClassX();
      }
    
      // So if you instantiated it in $this->x(), other methods should check if it
      // has been instantiated
      protected function yy() {
        if (!$this->obj instanceof classx) {
          // Call $this->x() to build $this->obj if not already done...
          $this->x();
        }
        $objmethod = $this->obj->methodx();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Object Factory Class which has a method called registerCreator as defined
I have a function which takes two current class level member variables and sets
On Class A I have this: protected function createTempTable() { $qry = ' CREATE
I have the object, which contain the list of objects. public class Product: IProduct
I have a protected function defined in a script block of a component defined
I have the following code: protected function safePath($path) { $path = (string) $path; $path
I have the following bit of code: protected function onEnterFrame(e:Event):void { var diff:Number; //
I have this reduce function: protected void reduce(Text key, Iterable<SortedMapWritable> values, Context context) throws
I have this code running in my onDestroy function: @Override protected void onDestroy() {
I have this: protected void Page_Load(object sender, EventArgs e) { nome_Txt.Text = Profile.dados_pessoais.nome; }

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.