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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:26:10+00:00 2026-05-27T04:26:10+00:00

i want to call a class method by a var (like this): $var =

  • 0

i want to call a class method by a var (like this):

$var = "read";
$params = array(...); //some parameter
if(/* MyClass has the static method $var */)
{
  echo MyClass::$var($params);
}
elseif (/* MyClass hat a non-static method $var */)
{
  $cl = new MyClass($params);
  echo $cl->$var();
}
else throw new Exception();

i read in the php-manual how to get the function-members of a class (get_class_methods). but i get always every member without information if its static or not.

how can i determine a method´s context?

thank you for your help

  • 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-27T04:26:11+00:00Added an answer on May 27, 2026 at 4:26 am

    Use the class ReflectionClass:

    On Codepad.org: http://codepad.org/VEi5erFw
    <?php
    
    class MyClass
    {
      public function func1(){}
      public static function func2(){}
    }
    
    $reflection = new ReflectionClass('MyClass');
    var_dump( $reflection->getMethods(ReflectionMethod::IS_STATIC) );
    

    This will output all static functions.

    Or if you want to determine whether a given function is static you can use the ReflectionMethod class:

    On Codepad.org: http://codepad.org/2YXE7NJb

    <?php
    
    class MyClass
    {
      public function func1(){}
      public static function func2(){}
    }
    
    $reflection = new ReflectionClass('MyClass');
    
    $func1 = $reflection->getMethod('func1');
    $func2 = $reflection->getMethod('func2');
    
    var_dump($func1->isStatic());
    var_dump($func2->isStatic());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C# when I want to call a static method of a class from
I want to call a validation method inside a shared gwt class that i
I want to call a redefined private method from an abstract parent class. I
I want to call a few static methods of a CPP class defined in
I want to make a YAHOO.util.Connect.asyncRequest call, which not is async. Just like open(method,
So here is the deal. I want to call a class and pass a
I want a pure virtual parent class to call a child implementation of a
I have created a separate class (let's call it class2.cs for example) and want
I want to call a web service method in javascript. (asp.net 3.5) I have
I am trying to do something like this in C# public class ParentClass {

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.