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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.