I am working in a larger existing software package, and in one little section I would like to change functionality, without changing the existing code.

How does one:
1. remove an existing function
2. and/or overwrite an existing function

I can't keep it from being written without getting more intrusive than I want.

Any thoughts?

    Are you refering to a function in the php build or this script you are talking about>?

      Looking to overwrite one of the functions that the existing software establishes, not a core php function

        Just find the file where is defines that function and modify that, that way you don't have to change any code whatsoever but you can SEVERELY screw up the functionality if you don't know what to change

          Except my goal is to not edit the original code base.

          If I can just call my alternate function base without editing the existing system it is going to leave me a cleaner future upgrade route. At least as far as locating the edits I make in the future. i.e. when the software is upgraded all my customization are located in one file, one place.

          Regardless of whether that is the best logic, it is a logic that works for my situation.

          Mainly I am just trying to figure out if it is possible to switch off, and/or overwrite and existing function.

            To my knowledge, there is no way to change a function definition once it has been defined. You will need to either create a new function with a different name and change the name of the function being called in those places where you need the change, or create a separate function definition file with the modified function to be included for that script, or alter the original function definition with an additional boolean parameter. The function would then have a different logical path driven by an if or switch statement based on that parameter being true; then in those cases where you want the different logic you simply call the function with the additional parameter as true. (Make it default to false in the function argument list so that you do not have to change the function calls that are to use the original functionality.)

              have you thought of simply commenting out where that function is called and/or located within your code, and than creating a text file log of the files you have altered and which line the changes started on?

              This way you will have a quick and easy to access path to all of your changes. Furthermore, if you just place comment brackets around the code, a matter of 4 backspaces will return the original code.

              for example:

              */
              the function would be located in here, now ignored by PHP
              /*
              

              to preserve simplification, place your alternate function right beneath, or just a comment explaining what youve done for future references...

              Hopefully thats somewhat on track with what you're aiming to accomplish, good luck!

                Thanks for the replies.

                I realize I could remove/comment-out + document changes.

                I was just looking for a system that allowed me to ... more gracefully (in the eye of the holder) maintain a customization package, that could live along side other software without modifying it.

                thanks for responses

                  okay heres a possibility....

                  // this is your config file
                  define("CUSTOM", 1);     // 1=yes 0=no
                  
                  // this is your functions file
                  function orignal_func()
                  {
                     if("CUSTOM"===1)
                    {
                       // this is your version of the function
                    }
                    else
                    {
                       // orignal version of function
                    }
                  }
                  

                    Ok, I think these are the way to do it:

                    Runkit_ Sandbox

                    runkit class adopt

                    runkit class emancipate

                    runkit constant add

                    runkit constant redefine

                    runkit constant remove

                    runkit function add

                    runkit function copy

                    runkit function redefine

                    runkit function remove

                    runkit function rename

                    runkit_ import

                    runkit lint file

                    runkit_ lint

                    runkit method add

                    runkit method copy

                    runkit method redefine

                    runkit method remove

                    runkit method rename

                    runkit sandbox output_ handler

                    runkit_ superglobals

                      Is this package written using PHPs object model? (Does the package define classes or only functions) If it uses classes, you may look into inheriting from any classes you wish to change, and adding or modifying functionality that way. This is how patches are applied to client-side applications. The same is true of PHP 5.

                        hmm...

                        if you are using an include file
                        can one perhaps

                        read the file as a string rather then include.... use reg ex to comment out the fucntion if you cannot modify the original file

                        then eval the remaining of the fille into working php?

                          Write a Reply...