我有一段代码我做了
abstract class WorkTypes
{
const Portfolio = 0;
const Study = 1;
}
function get_our_work ( $atts )
{
// see https://codex.wordpress.org/Shortcode_API
$work_type = (strcmp($atts['workType'],'ports') === 0) ? WorkTypes::Portfolio : WorkTypes::Study;
include "page-content/our_work.php";
}
并且理由$work_type
始终评估为WorkTypes::Study
,即使我100%确定$atts['workType']
等于'ports'
。所以我知道(strcmp($atts['workType'],'ports') === 0)
始终在评估false
。为什么呢?
答案 0 :(得分:0)
$ work_type =(strcmp($ atts ['workType'],'ports')<> 0)? WorkTypes :: Study:WorkTypes :: Portfolio;
如果你的$ atts ['workType']与'ports'不匹配,那么读取,那么WorkTypes :: Study它确实匹配所以使用WorkTypes :: Portfolio,无论哪个比较字符串不同。