Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

replace existing function in php

Options
  • 26-06-2007 11:24am
    #1
    Registered Users Posts: 648 ✭✭✭


    hi

    im using a CMS and i want to change a function without hacking the core

    the function is mosformatdate()

    id like to include a file that will ensure that my mosformatdate() is used and not the function from the API.

    however having two functions of the same name will give us an error !

    any way of replacing the first one?

    tnx


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Check out the override_function() function that comes with the PECL libraries.

    Example:
    [php]
    <?php
    function get_two($i) {
    return 2;
    }
    override_function('get_two', '$i', 'return 3;');

    echo get_two(1); //This echos "3"
    ?>
    [/php]
    If the above mosformatedate() function takes a single arg (say, $date), then in your include file you'd write something like:
    [php]
    <?php

    function my_mosformatdate($date) {
    //Insert action here
    }

    override_function('mosformatdate', '$date', 'my_mosformatdate($date);');
    ?>
    [/php]
    So every time someone calls mosformatdate(), the args get passed to my_mosformatdate() instead.


  • Registered Users Posts: 648 ✭✭✭ChicoMendez


    tnx

    i ame across that alright

    how would i install that on my shared hosting environment ?


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Depend on how they're set up.

    Assuming that you've tried to use this and gotten an error :) then they'll need to recompile PHP with the php_apd module (afaik).

    If it's a Windows environment then it's just a matter of adding the php_apd.dll extension to php.ini. I <3 Windows for the simplicity of that.


Advertisement