Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

replace existing function in php

  • 26-06-2007 11:24AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    tnx

    i ame across that alright

    how would i install that on my shared hosting environment ?


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭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