SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    ifdef like behavoiour in php somehow?

    is it possible to do what ifdef allows in c, in php? i'm putting in debugging code which involves creating a file to write to, haveing global $file_hanlde; at the top of all the functions, wrting to the file using the file handle in various functions, etc. this debugging code is all over the place. it'd be nice to be able to remove it from the php execution when not debugging, and be able to turn it all back on again easily and quickly should another problem arise in the future. that's what c's ifdef allows. you wrap bits of code in #ifdef DEBUG
    turn on and offable code here
    turn on and offable code here
    #endif

    then define DEBUG at the start of the code, or don't, to turn on or off the turn on and offable code.

    how would you do that in php?

    thanks.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I would use an object either a dedicated debug or logging object. Then it is only a matter of flipping a switch to disable debug logging.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    What is the functional difference between a commented ifdef and

    PHP Code:
    if (defined('foo')) {
    ...


  4. #4
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    > I would use an object either a dedicated debug or logging object. Then it is only a matter of flipping a switch to disable debug logging.

    right, yeah, ok. thanks.

    > What is the functional difference between a commented ifdef and ....

    urm, probably not a lot. nicer to completely hide code from parser when not needed but yeah.. ok, thanks.

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johnyboy View Post
    > I would use an object either a dedicated debug or logging object. Then it is only a matter of flipping a switch to disable debug logging.

    right, yeah, ok. thanks.
    Personally, I use log4php, where I can enable/disable everything in a configuration file
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •