Ok I have a string…
$a_string = "Product";
and I want to use this string in a call to a object like this:
$this->$a_string->some_function();
How the dickens do I dynamically call that object?
(don’t think Im on php 5 mind)
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.
So you the code you want to use would be:
This code implies a few things. A class called
Productwith the methodsome_function().$thishas special meaning, and is only valid inside a class definition. So another class would have a member ofProductclass.So to make your code legal, here’s the code.
Then you can call it with this: