![]() |
eval - seperate instace.
Does eval() create a seperate parsing instance? to clear up the question are any variables function and classes not available within the eval() function? the reason I ask is because out of curiosity I created this...
PHP Code:
|
You don't need to use eval for the thing you are trying to achieve, you could just replace:
PHP Code:
PHP Code:
PHP Code:
Quote:
|
Quote:
eval simply evaluates the code string as if it were hard-coded at that point in the script -- the variables, functions, etc. are all available in the current scope just like regular code.Your function seems a little odd. What would the advantage be of calling $object->t_display('blah') over $object->template->display('blah')? The former seems (to me) counter-productive since you're in essence breaking down the owner/member object relationship... in broad terms you're calling a method (function) "belonging" to $object when that method actually doesn't (shouldn't) belong to it; display belongs to template, not to the $object directly. But that's an aside, and I'm sure you have perfectly valid reasons for taking this particular approach.There are a number of things that I don't particularly feel are good approaches in your function, but since you didn't ask for comments on the actual code, I'll leave those out of this post. I would like to say however that you can use call_user_func_array as an alternative to eval. Say for example that the string which you would have evaled turned out to be: $this->template->display('blah', 'moo'); then you can use call_user_func_array in the following manner:PHP Code:
In the context of your function, the appropriate variables to use would be: PHP Code:
A revised alternative (not that you asked for one) might be something along the lines of: PHP Code:
Edit: sjaq beat me to it... guess that serves me right for drafting a post then wandering off for a cup of tea before submitting it! |
Actually if you have any comments and such I'd like to see in order to improve them and the reason why I chose that was actually out of simple curiosity something like a proof of concept.
|
| All times are GMT. The time now is 08:31 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0