eval in outside object use inside other object context
Posted: Sat Sep 27, 2008 4:53 pm
Title says it all
Use case:
Piece of code in the db. Using a class to get it and eval() it. Problem is that the context wherein the code is eval'd is not the context I won't. The context that should be the scope of the eval'd code is the place that calls the code that extracts the code out of the db.
Eg:
Use case:
Piece of code in the db. Using a class to get it and eval() it. Problem is that the context wherein the code is eval'd is not the context I won't. The context that should be the scope of the eval'd code is the place that calls the code that extracts the code out of the db.
Eg:
Code: Select all
class A {
private $loader;
public function setLoader(ILoader $loader) {
$this->loader = $loader;
}
public function specialFunction() {
$this->loader->load('somename'); // should have same effect as require_once('somename');
}
}
class DbLoader implements ILoader {
public function load($file) {
// extract code out of DB and eval it;
}
}
class RequireLoader implements ILoader {
public function load($file) {
// require = file_get_contents + eval
}
}
interface ILoader {
public function load($file);
}