Home  >  Article  >  Backend Development  >  The use of constant function in PHP

The use of constant function in PHP

PHP中文网
PHP中文网Original
2017-07-03 17:29:401611browse
<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>;

Reference address:

The above is the detailed content of The use of constant function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn