Maison > Article > développement back-end > L'utilisation de la fonction constante en PHP
<span style="color: #0000ff"><span class="refname"># constant — <span class="dc-title">返回一个常量的值</span></span><br>interface</span><span style="color: #000000"> Test{ </span><span style="color: #0000ff">const</span> BAR = 'foobar'<span style="color: #000000">; } </span><span style="color: #0000ff">class</span><span style="color: #000000"> Foo{ </span><span style="color: #0000ff">const</span> BAR = 'foo_bar'<span style="color: #000000">; } </span><span style="color: #800080">$test</span> = 'BAR'<span style="color: #000000">; </span><span style="color: #0000ff">echo</span> <span style="color: #008080">constant</span>('Test::' . <span style="color: #800080">$test</span><span style="color: #000000">); </span><span style="color: #0000ff">echo</span> <span style="color: #ff00ff">PHP_EOL</span><span style="color: #000000">; </span><span style="color: #0000ff">echo</span> 'Foo::' . <span style="color: #800080">$test</span>;
Adresse de référence :
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!