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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:45:43+00:00 2026-06-04T20:45:43+00:00

here is an example class: public class example { private $foof; public function __construct()

  • 0

here is an example class:

public class example
 {
     private $foof;         

     public function __construct()
     {
          $this->foof = $this->foo;
     }

     public function foo($val=0)
     {
             // do something...
     }
 }

So basically, in the constructer of the sample code, is it possible to assign a class method to a variable?

Ultimately what i want is to have an associative array with all the class methods aliased in it…that possible in php?

  • 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-04T20:45:45+00:00Added an answer on June 4, 2026 at 8:45 pm

    In PHP5.3+ (which you should be using anyway!) you can simply create an anonymous function which calls your method:

    $this->foof = function() {
        $this->foo(1);
    };
    

    However, you cannot call it using $this->foof() – you have to assign it to a variable first: $foof = $this->foof; $foof();


    In older PHP versions you cannot easily do this – create_function() does not create a closure so $this is not available there.

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

Sidebar

Related Questions

Example: Class A { public function __construct() { $this->b_Instance = new B(); } public
As I read here http://www.theserverside.net/tt/articles/showarticle.tss?id=NHibernate for example public class Department { private int id;
here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
Here is code example class A{ int i; public: A(int i) : i(i) {}
Here is an example of what I would do in Visual Basic: Public Class
For example I have a file name call A.java. Here its structure: public class
I just wanted to confirm the difference here, take this as an example: class
I can't get past this issue I am having. Here's a simple example: class
The fictional example here. Suppose I designed a class named IODevice. This class already
Please consider this -probably poorly written- example : class Command; class Command : public

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.