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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:07:11+00:00 2026-06-18T07:07:11+00:00

I would like to create a property which is a class in and of

  • 0

I would like to create a property which is a class in and of itself and add other methods to it within the “parent” class MyName, so that I would be able to do something like

$myname = new MyName();
$myname->event->post($params);

I’ve tried the following, but it doesn’t work:

class MyName {
    public function __construct() {
        $this->event = new stdClass();
        $this->event->post = function($params) {
            print_r($params);
        };
    }
}

$x = new MyName();
$x->event->post(array(1, 2, 3));

Which simply ends up flagging the following fatal error:

Fatal error: Call to undefined method stdClass::post() in C:\xampp\htdocs\Arkway\recreation\primepromotions\api\classes\FacebookWrapper.php on line 25
  • 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-18T07:07:12+00:00Added an answer on June 18, 2026 at 7:07 am

    You could use __call to access an internal array of closures, perhaps something like this:

    class MyName {
      public function __construct() {
         $this->event = new EventObj();
         $this->event->post = function($params) {
              print_r($params);
          };
      }
    }
    
    class EventObj {
    
      private $events = array();
    
      public function __set($key, $val) {
        $this->events[$key] = $val;
      }
    
      public function __call($func, $params) {
         if (isset($this->events[$func])) {
           call_user_func_array($this->events[$func], $params);
         }
      }
    }
    
    
    $x = new MyName();
    $x->event->post(array(1, 2, 3));
    

    Output:

    Array
    (
      [0] => 1
      [1] => 2
      [2] => 3
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a class that runs something (a runnable) at regular
i would like create a array of structure which have a dynamic array :
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create an application which can learn to classify a sequence
I'm trying to create a test class which organizes its test methods using inner
I have a validation class which I would like to use to check all
I am wanting to create a Model that has a property of Service which
I have the following classes which I would like to map using NHibernate class
I would like to create a simple drop down list with static values which
I would like to create a compiled query which uses reusable where predicates. An

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.