views:

57

answers:

1

Ok, I'm allowing the uploading of files which can have multiple functions in them. I need to be able to somehow error trap the include_once so that if the function_exists already and that function is being called within the file that is uploaded, than it, either 1 sends an error message, or 2 doesn't include the file at all.

Any Ideas?

I've done this: @include_once($filename); but than I get a blank page instead of an error message.

Or is there a better way to do this with the filename and filepath?

+1  A: 

What version of PHP are you using? With namespaces in the recent versions you can get around the function exists conflict.

Otherwise you can use the tokenizer functions (http://us.php.net/manual/en/function.token-get-all.php, http://us.php.net/manual/en/tokens.php) with T_FUNCTION and parse them out, keep a file or db table of existing functions and when you upload a new file check it against the table and add new ones.

Hans
Thanks for your feedback. I'm using the current version of php, but others may not be using that version. In any case, I'm thinking of the `create_function` php function for some reason to make the functions unique, instead of using include_once to add the functions, for overall compatibility.
SoLoGHoST
But don't you now have to worry about your variable names and conflicts? And, you won't be told about those conflicts upon parse, like you do with functions. That will be harder to spot bugs. Just my $.02.
Hans