There is such a line in the PHP code:

cPAGETYPE=='portal'?define('cPAGEPATH','templates/portal/'.$kernel['settings'] 'template__portal'].'/'):define('cPAGEPATH','templates/admin/'.$kernel['settings'] 'template__admin'].'/'); 

Question: what happens here and how to read it? What does the sign "?" before the first define and ":" before the second define?

  • one
    Well, if you do not pay attention to the ternary operator, not everything is so bad. Most likely this is a kind of config, where the preliminary value of the constant is further redefined by its code. Similar things can be found in C libraries, when variants of the values ​​of some directives determine the values ​​of others. - KiTE
  • >> The worst thing is to supply values ​​for a constant based on some conditions. What do you say, is it better to store the axis / root in a global variable?) Or is it possible to call the definition function every time? @KiTE, only ugly use or am I still not seeing something? For example define('cPAGEPATH', cPAGETYPE=='portal'?$v1:$v2) - Sh4dow
  • Constant - wikipedia. "preliminary value of a constant further on the code also redefines it" 2 is two !!!! This is a constant. 2x2 = 4 - IT IS UNREAL TO DISPOSE !!! This is a constant and a point here! And a variable is something that can change its value. 2 * x = y - something like that. - Stanislav Komar
  • You are trying to prove directly that 2 can be equivalent to 4th ... depending, for example, on the weather. - Stanislav Komar
  • 3
    @Stanislav Komar, in programming it is somewhat different. - Oleg Arkhipov

2 answers 2

 if (cPAGETYPE == 'portal') { define('cPAGEPATH','templates/portal/'.$kernel['settings'] 'template__portal'].'/'); } else { define('cPAGEPATH','templates/admin/'.$kernel['settings'] 'template__admin'].'/'); } 

Ternary conditional operation

Ternary conditional operator in PHP

    Analogue the classic way:

     if( cPAGETYPE=='portal' ){ define('cPAGEPATH','templates/portal/'.$kernel['settings']['template__portal'].'/'); }else{ define('cPAGEPATH','templates/admin/'.$kernel['settings']['template__admin'].'/'); } 

    The author of this piece of code was a little too smart when he misused the ternary operator .