Hi,
I am reusing code using include() / require() but I find that things like "return" and the "__FUNCTION__" don't work in the normal way because the scope is limited to the include file.
Is there a way of storing code in a text file, and have it evaluated as code inline with the other code, as if it were actually part of the other code?
Thanks in advance,
Tim.
reusing code
Moderator: General Moderators
Have a look at http://www.php.net/eval
(notice that you would need to make sure the parts with php code also need an opening <?php and closing ?> tag...)
(be warned that blind use of eval is a source of security problems...)
(notice that you would need to make sure the parts with php code also need an opening <?php and closing ?> tag...)
(be warned that blind use of eval is a source of security problems...)
Thanks for getting back.
I played around with eval() and sadly it seems to operate in the same way.
example
I played around with eval() and sadly it seems to operate in the same way.
example
Code: Select all
function tester(){
eval("echo __FUNCTION__;");// this echoes nothing
eval("return false;") // this does not halt execution of the function
echo "hello"; // this is still echoed because the return did not happen as usual
}- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Thanks for getting back,Kieran Huggins wrote:code reuse... isn't that what functions and classes are for?
What are you trying to do exactly Tim?
I am trying to use the following code in several functions -
Code: Select all
<?php
$this->log[] = __FUNCTION__" caused an error";
return false;
?>- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: