PHP未定义的常量错误,同时使用非!defined
值,任何其他选项。
我的代码:-
<a href="http://'.<?php !defined(DOMAIN) ? print('localhost') : print(MY_DOMAIN); ?>.'" target='_blank'>My Website</a>
但这给了我错误:
<a href="http://<br />
<b>Notice</b>: Use of undefined constant DOMAIN - assumed 'DOMAIN' in <b>C:'Program Files (x86)'Apache Software Foundation'Apache2.2'htdocs'url.php</b> on line <b>3</b><br />localhost" target='_blank'>My Website</a>
如果我不使用:-,它不应该只打印localhost吗
define('DOMAIN', 'example.com');
有没有其他方法可以指定!定义值?
您必须将常量的名称用引号括起来。
<a href="http://'.<?php !defined("DOMAIN") ? print('localhost') : print(DOMAIN); ?>.'" target='_blank'>My Website</a>
否则它会这样工作:(因为你要传递const的值)
define("DOMAIN", 'example.com');
defined(DOMAIN)
将等于defined('example.com')