Macai Posted July 2, 2007 Share Posted July 2, 2007 This may sound quite weird, but I'm curious if it is possible to "undeclare" a function. What I mean by this is, take a user function which has already been declared, and then remove it from existence so that it might be redeclared as something else. (If you didn't notice yet, I am using the eval() function) Here's an example what I want to do: function SomeFunc() { //code here } undeclare('SomeFunc'); // this is a hypothetical function SomeFunc(); //try to call a function that no longer exists The desired result would be: Fatal error: Call to undefined function SomeFunc() in ... on line ... Is there any way this can be accomplished? I checked the documentation's section on Function Handlin Functions, but alas, there was nothing there. Is there perhaps some sort of workaround or the such that one of you guys can think of? Thanks --Macai Link to comment https://forums.phpfreaks.com/topic/58019-undeclare-a-function/ Share on other sites More sharing options...
trq Posted July 2, 2007 Share Posted July 2, 2007 Sorry, but the answer is no. Once a function is within scope, it stays there. Link to comment https://forums.phpfreaks.com/topic/58019-undeclare-a-function/#findComment-287568 Share on other sites More sharing options...
Macai Posted July 2, 2007 Author Share Posted July 2, 2007 Ah, well, that's unfortunate. I wonder if something of the sort could potentially be created, and if so, how hard it would be to code. Thanks anyway, though! Link to comment https://forums.phpfreaks.com/topic/58019-undeclare-a-function/#findComment-287570 Share on other sites More sharing options...
trq Posted July 2, 2007 Share Posted July 2, 2007 Exactly what is it your trying to do? There may be ways around it. For instance you may be able to define the second function with a different name. eg; <?php function foo() { echo "this is foo"; } if (function_exists("foo")) { function foo2() { echo "this is new foo"; } foo2(); } else { foo(); } ?> Need to know more about what it is your doing. Link to comment https://forums.phpfreaks.com/topic/58019-undeclare-a-function/#findComment-287573 Share on other sites More sharing options...
Macai Posted July 2, 2007 Author Share Posted July 2, 2007 Well, what I'm doing is actually writing a complete application in PHP. However, the code in the functions must be changeable on the fly. So when I update example.php, and want the code to changes in the file to automatically take effect in a PHP script actively in runtime. Now, I have devised a potential workaround which I'll be playing with. That being, have the functions declared, sure, but compare the last modified date to the last load date. If it's been modified since loading, the file just gets loaded into memory and I use eval() to execute it. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/58019-undeclare-a-function/#findComment-287586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.