Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i need to create a class by name

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
$obj = new "myclass"

I need to create a Php Class by name
can i do it ?


 
Do you mean instantiate an existing class, or actually run code to create a new class that does not yet even exist?

$obj = new "myclass" is a meaningless piece of code. The "new" keyword means to create a new object of an existing class, not to create a new class. Thus the quotes make no sense, because you are still just using a word, with no variable interpolation. $obj = new myclass;, on the other hand, is a perfectly normal piece of code, assuming there is a class already existing called "myclass", but I guess it doesn't accomplish what you want.

If you want to actually run code that defines a new class, you would probably want to build a string that consists of the code you want to run, and then run it with the eval($your_string) function. (see
Failing that, please explain in more detail exactly what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top