terrordrone Posted September 7, 2009 Share Posted September 7, 2009 Hello.. I am taking in php code (which returns a true or false) from a html textarea as input.. which i would like to run as some execution condition checking. I am then creating a anonymous function out of it using 'create_function' However sometimes if the code is not right.. then i get some error... Ideally i would like to check if the code submitted can compile during the input of the code itself.. I am aware that this is not a good idea... keeping in mind the security issues.. Keeping aside the security issues.. How do i go about this ? (checking if that piece of code submitted compiles right) Link to comment https://forums.phpfreaks.com/topic/173374-checking-if-code-can-compile/ Share on other sites More sharing options...
deth4uall Posted September 7, 2009 Share Posted September 7, 2009 PHP doesn't compile, the server only checks syntax as it runs... Link to comment https://forums.phpfreaks.com/topic/173374-checking-if-code-can-compile/#findComment-913961 Share on other sites More sharing options...
corbin Posted September 7, 2009 Share Posted September 7, 2009 You could use the -l flag on the PHP binary to check it. You would have to use eval() or something. By the way, unless you absolutely trust your users, that's not secure at all. Link to comment https://forums.phpfreaks.com/topic/173374-checking-if-code-can-compile/#findComment-913962 Share on other sites More sharing options...
terrordrone Posted September 7, 2009 Author Share Posted September 7, 2009 Yea.. sorry.. i meant syntax checking only.. Currently as i load the code from the database.. i am creating a anonymous function and then calling it.. so before putting it into the database.. i need to check if the syntax of the input code is right.. @corbin.. yea only a select few get to upload code... I do not have a binary.. Link to comment https://forums.phpfreaks.com/topic/173374-checking-if-code-can-compile/#findComment-913979 Share on other sites More sharing options...
terrordrone Posted September 8, 2009 Author Share Posted September 8, 2009 even if its eval.. the whole script ends... i want something like a try-catch .. where i catch any error in syntax Link to comment https://forums.phpfreaks.com/topic/173374-checking-if-code-can-compile/#findComment-914530 Share on other sites More sharing options...
Mark Baker Posted September 8, 2009 Share Posted September 8, 2009 create_function() should return an error Link to comment https://forums.phpfreaks.com/topic/173374-checking-if-code-can-compile/#findComment-914550 Share on other sites More sharing options...
terrordrone Posted September 8, 2009 Author Share Posted September 8, 2009 I am checking if 'create_function' is returning false... anyway.. will double check and post back.. Link to comment https://forums.phpfreaks.com/topic/173374-checking-if-code-can-compile/#findComment-914563 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.