What I want to do is this:
When I write a class and the class instantiates another class, I want to import that class with an require_once. Just the way I do so in Objective-C. But instead of using plain require_once function and messing around with paths and string concatenation, I would prefer something like:
importClass('myclass');
but I’m afraid that it’s impossible to write a function that will include code. If I would do that in the importClass() function, I would include the class code into the implementation block of the function, which of course is nonsense. So what options do I have here?
It’s not impossible at all. You can write this function:
The only caveat is that any global variables declared or used inside that file will now be local to
importClass(). Class definitions however will be global.I’m not sure what this really gives you however but you can certainly do it.