473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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:
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
1 5038
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

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

Similar topics

0
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful...
1
by: P L | last post by:
I have codes with blocks like this: void h() { .. .. .. a; b1; b2; ..
13
by: seemanta dutta | last post by:
Greetings C gurus, I have used preprocessor directives since a very long time. But whenever I see some professional piece of C code, the linux kernel for example, I get literally confused by the...
6
by: Michael B Allen | last post by:
Which is the preferred method for preprocessor tests and why? #ifdef XYZ or #if XYZ or #if defined(XYZ) and
1
by: lukwagoroy | last post by:
Loaded 'ntdll.dll', no matching symbolic information found. I'm writing a small program. It compiled and run. But when trying to debug by select, I got the following error messages: Loaded...
3
by: Steve Peterson | last post by:
Hello Is there a more elegant .NET way to pass info from one page to the next without the querystring "?Id=45" (example) way?. I have an app in wich I would like to pass information from one...
8
by: kk_oop | last post by:
Hi. In our domain, we have to vary a lot of code based on a radar type (of which there are 3--for now). The legacy code acheives this by heavy use of #ifdef macros sprinkled throughout the code. ...
1
by: ajaypatel19 | last post by:
I have code like #ifndef ABC #define ABC ... ... #ifdef XYZ ... ..
6
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
46
by: mattia | last post by:
I've see in some code: #ifdef __cplusplus extern "C" { #endif what does it mean? Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.