Jump to content

Undeclare a Function


Macai

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.