unset a function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xhunter
    New Member
    • May 2007
    • 42

    unset a function

    is it possible in anyways to unset a function

    what my problem is that I have to php files which declare the same function, and if i include them both they result in an error that it can not declare the function again,

    those are not my php files, so I can use if(!function_ex ists()) in any of them,

    I found "rename_functio n()" but it is for PECL, can't use it

    what I am trying to do is , if lets say the conflicting function name is "func"

    include 'first file.php';
    rename_function ('func','func2' ); // or unset it for now
    include '2nd file.php';
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, xhunter.

    Try manually renaming the function in each file and using a variable to store the name of the function you want to call.

    E.g.,
    [code=php]
    include 'file1.php'; // Defines 'function1'

    $func = 'function1';

    $func(...);

    include 'file2.php'; // Defines 'function2'

    $func = 'function2';

    $func(...);

    [/code]

    Comment

    • xhunter
      New Member
      • May 2007
      • 42

      #3
      thanx,
      but as I said, I can't change those files, not because I don't have access but because they are files from 2 sets of scripts that I have that work independently, and I just want to use some of variables set in them.

      and I don't really need to use that specific function when including both of the files,
      I just don't want to get the error that I can't redeclare it, so I was thinking to unset one of them to prevent conflicting.

      Comment

      • xhunter
        New Member
        • May 2007
        • 42

        #4
        what the function really is, is the "iif()" function commonly used,

        now I can not include to files that declare the same function. and both of them need to be called this way.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, xhunter.

          The best advice I can offer you is to copy the functions that you need out of one of those files and creating a separate file so that there is no naming conflict.

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            You should make it a point to use classes since PHP doesn't support namespaces. If you had them all as static functions in a class, you'd be fine.

            Comment

            Working...