Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to redeclare a function in php

edited May 2007 in Vanilla 1.0 Help

I'm new to php ... but:

I try to build my own application, using the framework of vanilla to get user-authentification, delegates, themes, styles and all the other good things into my application.

No I want to avoid mixing of my own files and the vanilla files, and I want to avoid hacking vanilla files. Works better then expectet, but I have one problem: Framwork.Functions.php defines many functions. Most of theme can stay, but I would like to change some of them, especially ThemeFilesPath. But I can't redeclare it, and don't want to change Framwork.Functions.php - what to do!



  • Options
    Good question.

    I would like to customize GetUrl, and a few others but haven't for that reason.

    Maybe create an appg/functions.php file with declarations of all core function names? $Func['ThemeFilesPath'] = 'ThemeFilesPath';

    And then everywhere in the core the function is called like this:$Func['ThemeFilesPath']();

    If you want to ovverride the function, you copy it to get basic functionality and parameters and then add $Func['ThemeFilePath'] = 'MyVersionOfThemeFilePath'; to conf/functions.php.
  • Options
    I think you can override functions using the object factory somehow cant you? I'm not sure...maybe you can only override classes?
  • Options
    MarkMark Vanilla Staff
    As far as I can see, there is no way to do it - which really P's me off. I've done some digging looking for the ability to do this in the past. PHP has a function_override function, but it only works on PHP's built-in functions, not on custom user-built functions.

    What did you want to change about the ThemeFilePath function? I've been wanting to make some changes to it, too...
  • Options
    I just want to include one more path to look for files! No great thing at all!
  • Options
    Hi Mark!

    What about the idea, to put all the functions into a class? Then we could overwrite the class! But it would be a huge change to the core and many extensions... :-(

  • Options
    MarkMark Vanilla Staff
    I think I might be changing that function as it's been bugging me quite a bit lately... I don't like how it assumes the theme files are in the theme folder - what if I wanted to put the theme file in an extension folder, for example?

    Is that the type of thing you are trying to do?

    I don't like the idea of putting the functions into a class. method calls vs function calls are way slower in php.
  • Options
    Having an array of theme-locations would be nice to!

    What I try to do is a whole new application, using the vanilla/peoples framework. Somthing like Gossamer Threads Links.
  • Options
    Drupal allows overriding its theme functions very well.
    So if you have a function like this
    <?php function theme_item_list($items = array(), $title = NULL) { ?>
    you can override it using this
    <?php /** * Catch the theme_item_list function, and redirect through the template api */ function phptemplate_item_list($items = array(), $title = NULL) { // Pass to phptemplate, including translating the parameters to an associative array. // The element names are the names that the variables // will be assigned within your template. return _phptemplate_callback('item_list', array('items' => $items, 'title' => $title)); } ?>

    you should check out Drupal Template api and see how it works
    Here is the documentation of overriding Drupal theme functions
  • Options
    Being able to put theme files in an extension folder would rock. Then you could make some groovy extensions that change the way Vanilla looks as well as works in one swift motion. Would have rocked a few months ago when I was messing with gettin Vanilla to look/feel like Digg. Would have made it easier.
This discussion has been closed.