PHP始终不为空

PHP始终不为空,php,Php,我的cms中有一段代码: <ul class="subsection_tabs" id="tab_group_one" style="clear:none;"> <?php if ($this->getChildHtml('description')==NULL) { echo '<div id="trollweb_1"></div>'; } else echo(' <li class="tab"><a href=

我的cms中有一段代码:

<ul class="subsection_tabs" id="tab_group_one" style="clear:none;">
    <?php if ($this->getChildHtml('description')==NULL) { echo '<div id="trollweb_1"></div>'; } else echo('
    <li class="tab"><a href="javascript:void(0);" id="trollweb_1" onClick="trollweb_tabs(1)" class="active"><h4>' . $this->__('Product Description'). '</h4></a></li> '); ?>
问题是它总是输出“else”。尽管我没有在后端填写描述,而且它是空白的


如何修复此问题?

如果您尝试不仅测试
NULL
,还测试空字符串,那么您应该这样做

$childHtml = $this->getChildHtml('description');
if (empty($childHtml))
相反

EDIT:正如VolkerK所说,
empty('0')
也返回false,所以解决方案取决于您的需求。看起来,就像您在寻找字符串解决方案一样,这是一个可行的选项,只要您没有“0”作为值。

可能getChildHtml()总是返回字符串(非空)。测试环境中的字符串可能只包含空格。
在这种情况下,删除它们,您只需检查字符串的长度

if ( 0<strlen(trim($this->getChildHtml('description'))) ) { 
if(0getChildHtml('description')){

什么是
$this
$this->getChildHtml('description')
返回什么?我怀疑在不知道这些问题的答案的情况下,任何人都不能帮助你。是的,确保$this->getChildHtml('description')不返回NULL。请提供更多信息。$this->getChildHtml('description'))返回可在cms(Magento)后端完成的文本区域。我将文本区域留空。空仅适用于变量,不适用于方法调用的返回值: