I have a method in a variable named class that I need to call dynamically, how can I call this:
$foo = "object"
Where object is a specific class
How do I call this in PHP?
$foo::method()
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.
The wording of the question is confusing but from what I understand, if you want to set
$footo a specific class, lets call itFooyou can do this:Here is our class
FooIf you want to access a class variable
Fooand set it to a variable you can do this:Also to clarify
$foo::method()implies that$foois a static class, and static classes cannot be instantiated but they can call on its class methodmethod()by using the scope resolution operator (::)Hope this helps.