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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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…Or in 5.3 with static methods, it gets a bit harder: