Is there an elegant alternative in PHP for '#ifdef'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samdorrell4
    New Member
    • Jan 2012
    • 2

    Is there an elegant alternative in PHP for '#ifdef'

    I'd like to use Macros to control what functions/variables are used in order to test my PHP file. But I know PHP doesn't do Macros, so what would someone suggsest is an elegant way to do this? The reason for having the macros is so I can easily switch between one themeID and another while still having full control over each theme! Please ignore the fact that I've used some C constructs and others PHP!

    For instance:
    Code:
    #define themeID1
    #ifdef themeID1
    #   define $BANNERNAME 'flowers.jpg'
    #else
    #   ifdef themeID2
    #       define $BANNERNAME 'robots.jpg'
    #   endif
    #endif
    
    // Now I'm going to add this banner to my wordpress 
    // thematic theme!
    function add_banner(){ 
        global $BANNERNAME;
        $styledir = get_styledir(); 
        echo '<img src="'.$styledir.'/'.$bannerName.'">';
    }
    add_action('thematic_header','add_banner',3);
  • samdorrell4
    New Member
    • Jan 2012
    • 2

    #2
    Ah, I think I made a mistake earlier, apparently I can just do this.

    Code:
    <?php
    $themeId = 1;  
    switch ($themeId){
        case (1):
            $bannerName = 'flowers.jpg';
            break;
        case (2):
            $bannerName = 'robots.jpg';
            break;
    }
    
    //my functions
    ...
    ...
    ?>
    Is this a decent way to do things in PHP?
    Last edited by samdorrell4; Jan 17 '12, 04:23 PM. Reason: mistake with [code] tags

    Comment

    Working...