Eval

Hello,

I am currently implementing a module that can be customized for/by my customers without touching the main solution. One problem that I need to solve here is that it has to be integrated into my main solution without me knowing what kind of wild stuff my customers wish to implement.

My idea now is this:

  • I have a table with Menu-entries that can be edited by my customers (they can build their own menus in one fixed menu-place)
  • One of the columns of the menu table is called “method” and my customers are supposed to enter the name of the method of their module that is to be executed if a users clicks on that menu entry
  • I then simply eval() this method and the rest is up to them

While this seems to work fine, I want to make sure that eval() is save to use in cases like this. Half of my navigation logic will be based on this, so I want to make sure…

Thanks!
Patrick

Patrick,

Sure - eval can be used like this. The one caution about using eval() is that it can’t be compiled, so it must be evaluated “on the fly” - and thus might be a bit “slower” in performance (not enough to really notice, but there is it slower than writing the code so it will compile into bytecode).

If you can live with that - then you should be just fine. I’ve used a similar technique and it works very well.

Thanks Bob!