Php uses variables to dynamically create class object usage examples, variable examples
This example describes how php uses variables to dynamically create class objects. We will share this with you for your reference. The details are as follows:
This is an object that can dynamically create classes using variables. It is used to create objects based on the $ pay_code variable value.
For example, the next example is to create a class T object $ payment. Then you can use it. It seems like a new knowledge point. In fact, it is not actually a skill in programming.
$ Pay_code = 'T'; $ payment = new $ pay_code (); echo $ payment-> ep (); class T {function ep () {return 'I am the method in T! ';} Function _ toString () {return' This is a T class ';} class W {function ep () {return' I am the method in W! ';} Function _ toString () {return' This is a W class ';}}