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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:34:52+00:00 2026-06-03T02:34:52+00:00

how can i access the second property or method in this statement $this->test->hello(); In

  • 0

how can i access the second property or method in this statement

$this->test->hello();

In my __get() I can only figure out how to figure out what the test property is. I want to be also be able to capture the ‘hello’ method call. and do some dynamic things with it.

So in short if I type

$this->test->hello()

I want to echo each segment

echo $propert // test
echo $method //hello

The issue is that my test is being used to instantiate a new class object from an outside class. The method hello belongs to the test class object.

I want to capture the method within my __get().

How can i do this?

EDIT:

public function __get($name)
        {
            if ($name == 'system' || $name == 'sys') {

                $_class = 'System_Helper';

            } else {

                foreach (get_object_vars($this) as $_property => $_value) {

                    if ($name == $_property)
                        $_class = $name;
                }
            }

            $classname = '\\System\\' . ucfirst($_class);
            $this->$_class = new $classname();

            //$rClass = new \ReflectionClass($this->$_class);
            $rClass = get_class_methods($this->$_class);
            foreach($rClass as $k => $v)
            echo $v."\n";
            //print_r($rClass);

            return $this->$_class;
  • 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-03T02:34:53+00:00Added an answer on June 3, 2026 at 2:34 am

    It seems you are after some kind of proxy class, this might suit your needs.

    class ObjectProxy {
        public $object;
    
        public function __construct($object) {
            $this->object = $object;
        }
    
        public function __get($name) {
            if (!property_exists($this->object, $name)) {
                return "Error: property ($name) does not exist";
            }
            return $this->object->$name;
        }
    
        public function __call($name, $args) {
            if (!method_exists($this->object, $name)) {
                return "Error: method ($name) does not exist";
            }
            return call_user_func_array(array($this->object, $name), $args);
        }
    }
    
    class A {
        public $prop = 'Some prop';
    
        public function hello() {
            return 'Hello, world!';
        }
    }
    
    class B {
        public function __get($name) {
            if (!isset($this->$name)) {
                $class_name = ucfirst($name);
                $this->$name = new ObjectProxy(new $class_name);
            }
            return $this->$name;
        }
    }
    $b = new B();
    var_dump($b->a->hello());
    var_dump($b->a->prop);
    var_dump($b->a->foo);
    var_dump($b->a->bar());
    

    Output:

    string 'Hello, world!' (length=13)
    string 'Some prop' (length=9)
    string 'Error: property (foo) does not exist' (length=36)
    string 'Error: method (bar) does not exist' (length=34)
    

    Example:

    http://ideone.com/dMna6

    It could be easily extend for other magic methods like __set, __callStatic, __isset, __invoke, etc.

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

Sidebar

Related Questions

How can hibernate can access a private field/method of a java class , for
Let's suppose I can access the following code: http://localhost/web/src/js/myApp.js Now I want to load
Why I can access Session object in Page_Load method in instance of System.Web.UI.Page, but
I learned something new while trying to figure out why my readwrite property declared
I can access to my package in /data/data folder. But i can't cp command
I can access Spring beans in my Servlets using WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); in
I can access and show self.view and see the frame in the log but
We can access the valueStack (and other objects of ActionContext ) using OGNL but
Can anyone let me know how can access an element of a list that
As you know anyone can access strings in an native application using a hex

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.