Does PHP have an equivalent of C/C++'s #ifdef?

前端 未结 6 1738
陌清茗
陌清茗 2021-02-19 05:53

I\'m trying to define a constant, but I don\'t want to redefine it if it\'s already been defined. Here\'s a C sample:

#ifndef BASEPATH
#define BASEPATH /mnt/www         


        
6条回答
  •  孤城傲影
    2021-02-19 06:51

    Use defined() and define().

    if (!defined('BASEPATH')) {
        define('BASEPATH', '/mnt/www');
    }
    

提交回复
热议问题