我習慣於使用PHP和JavaScript,但我現在已經開始在Coldfusion中開發一個項目。Coldfusion字符串== true或空==錯誤?
在PHP中,我習慣於字符串是「truthy」,空/ null是「falsy」。
這似乎並不適用於ColdFusion(特別是v8)。
我想作以下工作,但無法弄清楚如何使CF看到的truthy字符串:
<cfset x = "path\to\something.cfm">
<cfif x>
x is truthy
<else>
x is falsy
</cfif>
我總是得到錯誤:cannot convert the value "path\to\something.cfm" to a boolean
isBoolean()
排序作品,但感覺不夠健壯。- 似乎有不爲'isString() - 但是這將是問題,因爲上面反正
YesNoFormat()
奇怪給我同樣的錯誤(什麼我會雖然它應該做的完全相反)
最好的選擇是檢查Len(X),它將返回0或1+,1+評估爲true。 – Busches