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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:34:47+00:00 2026-05-26T20:34:47+00:00

This is somewhat a follow up to a previous question – but I’ve distilled

  • 0

This is somewhat a follow up to a previous question – but I’ve distilled the question down and have the “works” vs. “doesn’t work” cases narrowed down much more precisely.

My Goal:
I have a class MyClass that has an instance variable myFunction. Upon creating a MyClass object (instantiating), the constructor assigns the instance variable myFunction with the result of a call to create_function (where the code and args come from a db call).

Once this object of type MyClass is created (and stored as an instance variable of another class elsewhere) I want to be able to call myFunction (the instance variable anonymous function) from “anywhere” that I have the MyClass object.


Experimental Cases — below is my highly simplified test code to illustrate what works vs. what doesn’t (i.e. when the expected functionality breaks)

class MyClass extends AnotherClass {

     public $myFunction;

     function __construct() {

         $functionCode = 'echo "NyanNyanNyan";';

         $this->myFunction();

         /*Now the following code works as expected if put in here for testing*/
         $anonFunc = $this->myFunction;
         $anonFunc();   //This call works just fine (echos to page)!   

         /*And if i make this call, it works too! */
         self::TestCallAnon();       

     }

     public function TestCallAnon() {

          $anonFunc2 = $this->myFunction;
          $anonFunc2();
     }

}

However, if I do the following (in another file, it errors saying undefined function () in… within the Apache error log.

//I'm using Yii framework, and this is getting the user 
//objects instance variable 'myClass'. 

$object = Yii::app()->user->myClass; 

$object->TestCallAnon(); // **FAILS**

or

$func = $object->myFunction;
$func(); // ** ALSO FAILS **

In addition, several variations of calls to call_user_func and call_user_func_array don’t work.

If anyone is able to offer any insight or help that would be great :).

Thanks in advance!

  • 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-26T20:34:48+00:00Added an answer on May 26, 2026 at 8:34 pm

    I ended up solving this issue via a workaround that ended up being a better choice anyways.

    In the end I ended up having a static class that had a method to randomly return one of the possible identifiers, and then another method which accepted that identifier to build the anonymous function upon each class.

    Slightly less elegant than I would like but it ends up working well.

    Thanks to everyone for your efforts.

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

Sidebar

Related Questions

This is somewhat of a follow-up question to this question . Suppose I have
This is somewhat of a follow-up to an answer here . I have a
This is somewhat related to the question posed in this question but I'm trying
This is somewhat of a follow up to a question posted earlier last month.
Consider this somewhat of a follow up to this question . Essentially, the C++
This is a somewhat of a follow up to this posting but with a
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
This is somewhat asp.net MVC related only for example purposes but I was hoping
this is somewhat of an odd question. I wrote a C function. Its 'like'
This is somewhat of a sequel to Slow Exists Check . Alex's suggestion works

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.