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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:48:54+00:00 2026-05-30T11:48:54+00:00

How can I do multiple levels of de-referencing? For instance, in C#, we can

  • 0

How can I do multiple levels of de-referencing? For instance, in C#, we can keep appending a ‘.’ to access the next objects properties: string s, s.ToString(), s.ToString().ToUpper(). With PHP, I get to around $this->someobject, but $this->someobject->somethingelse does not appear to work.

Any ideas?

  • 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-30T11:48:55+00:00Added an answer on May 30, 2026 at 11:48 am

    Assuming you’re using PHP5+, and $this->someobject returns an object with a property called somethingelse; it should work.

    Similarly, this also works

    class Example
    {
        public function foo()
        {
            echo 'Hello';
            return $this; // returning an object (self)
        }
    
        public function bar()
        {
            echo ' World';
            return $this;
        }
    }
    
    $example = new Example;
    $example->foo()->bar(); // Hello World
    $example->foo()->foo()->foo()->bar()->foo(); // HelloHelloHello WorldHello
    

    Edit:

    Just as a further note, you don’t have to return self. Any object will suffice.

    class Example1
    {
        public function __construct(Example2 $example2)
        {
            $this->example2 = $example2;
            $this->example2->setExample1($this);
        }
    
        public function foo()
        {
            echo 'Hello';
            return $this->example2;
        }
    }
    
    class Example2
    {
        public function setExample1(Example1 $example1)
        {
            $this->example1 = $example1;
        }
    
        public function bar()
        {
            echo ' World';
            return $this->example1;
        }
    }
    
    $example = new Example1(new Example2());
    $example->foo()->bar(); // Hello World
    $example->foo()->bar()->foo()->bar(); // Hello WorldHello World
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a multi-tenant system with multiple different levels of access--sometimes even for the
I have a C# Class that can contain multiple children at multiple levels. Adding
I have a structure which can have multiple levels e.g. <li> <a class=viewdetails></a> <input
In Java, you can define multiple top level classes in a single file, providing
Can multiple SSRS share the same DB? We're getting into an SSRS customization scenario,
In C#, can multiple threads read and write to a Dictionary provided each thread
Is registering components on castle windsor thread-safe? I.e., can multiple threads simultaneously register components
DocumentsController#common_query can handle multiple different request styles. i.e. all docs in batch 4 or
I know you can combine multiple table-selects using a Join statement but is there
how i can put multiple buttons in scroll view with according to my requirement?

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.