By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,871 Members | 2,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,871 IT Pros & Developers. It's quick & easy.

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

P: 2
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:
Expand|Select|Wrap|Line Numbers
  1. #define themeID1
  2. #ifdef themeID1
  3. #   define $BANNERNAME 'flowers.jpg'
  4. #else
  5. #   ifdef themeID2
  6. #       define $BANNERNAME 'robots.jpg'
  7. #   endif
  8. #endif
  9.  
  10. // Now I'm going to add this banner to my wordpress 
  11. // thematic theme!
  12. function add_banner(){ 
  13.     global $BANNERNAME;
  14.     $styledir = get_styledir(); 
  15.     echo '<img src="'.$styledir.'/'.$bannerName.'">';
  16. }
  17. add_action('thematic_header','add_banner',3);
  18.  
Jan 17 '12 #1
Share this Question
Share on Google+
1 Reply


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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $themeId = 1;  
  3. switch ($themeId){
  4.     case (1):
  5.         $bannerName = 'flowers.jpg';
  6.         break;
  7.     case (2):
  8.         $bannerName = 'robots.jpg';
  9.         break;
  10. }
  11.  
  12. //my functions
  13. ...
  14. ...
  15. ?>
  16.  
Is this a decent way to do things in PHP?
Jan 17 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.