PHP eval() logical operator error

大憨熊 提交于 2019-12-11 16:58:34

问题


Why does

if (isset($_SESSION['location']) AND !empty($_SESSION['location']))

work while

if (isset($_SESSION['location']) && !empty($_SESSION['location']))

does not?

I'm using eval() to process PHP in a wordpress page. It makes no sense to me why PHP chokes on && and not AND. The docs don't say anything specifically and no one else seems to have a clear answer.

Thanks for your input.

EDIT

Not that it really matters, but I use eval() in a WP template:

            $sContent   = get_the_content();
            $sContent   = apply_filters('the_content', $sContent);
            $sContent   = str_replace(']]>', ']]>', $sContent);

            eval(' ?>'. $sContent .'<?php ');

回答1:


Wordpress converts the && to &#038;&.

I've run into an issue like this before, so it's good to know. I do most of the logic in that PHP WP template, so this is no big deal, jsut as long as I understand what's going on.

Thanks go to GigaWatt for pointing this out and reminding me of long lost memories.



来源:https://stackoverflow.com/questions/5437403/php-eval-logical-operator-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!