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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:14:54+00:00 2026-05-15T05:14:54+00:00

I am using the magic __call method in PHP. Sometimes the function I call

  • 0

I am using the magic __call method in PHP. Sometimes the function I call is a number. For example the class name is example, then sometimes I want to call example::32

Is this possible or should I look at another alternative.

  • 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-15T05:14:54+00:00Added an answer on May 15, 2026 at 5:14 am

    Sure it’s possible. You just need to change the call syntax. $foo->32() is not valid and will give a fatal error. But $foo->{'32'}() is valid syntax. Now, you can’t define a function 32, but you can use __call to execute it…

    class Foo {
        public function __call($f, $args) {
            echo $f;
        }
    }
    
    $foo = new Foo;
    
    $foo->32();  //Fatal Error
    
    $foo->{32}(); //Fatal Error
    
    $foo->{'32'}(); // "32" is printed
    
    $x = 32;
    $foo->$x(); //Fatal Error
    
    $x = '32';
    $foo->$x(); // "32" is printed
    
    $x = 32;
    $foo->{(string)$x}(); // "32" is printed
    
    call_user_func(array($foo, '32')); // "32" is printed
    

    Or in 5.3 with static methods, it gets a bit harder:

    class Foo {
        public static function __callStatic($f, $args) {
            echo $f;
        }
    }
    
    Foo::32();  //Fatal Error
    Foo::{32}(); //Fatal Error
    Foo::{'32'}(); //Fatal Error
    
    $x = 32;
    Foo::$x(); //Fatal Error
    
    $x = '32';
    Foo::$x(); // "32" is printed
    
    $x = 32;
    Foo::{(string)$x}(); //Fatal Error
    
    call_user_func(array('foo', '32')); //Fatal Error
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a class which has methods called using PHP's __call() magic
For example this class: class A{ public function __call($func, $args){ if($func == 'something') call_user_func_array($this->_some_magic,
I am using a magic getter/setter class for my session variables, but I don't
I am using PHP's magic __set and __get methods to access a private array
I'm writing a simple image upload function with php + image magick using amazon
Possible Duplicate: Magic numbers of the Linux reboot() system call I was asked this
Instead of using $this->fetchAll('email = ?',$email)->current() inside the model class, is there a way
I've created a guess-the-number game using jQuery and PHP, and while it works fine
I am using the __call magic within some of my mvc code to produce
Using magic strings in C# really unsettles me, so I'm thinking of using the

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.