duanjingwei7239 2019-04-17 09:38
浏览 333
已采纳

PHP忽略了var_dump(),die()等代码

This is a very weird situation like I've never seen in my life. For some reason PHP is ignoring a lot of code inside a static function.

Here is the example:

static function describe($tableName, $columns = '*') {
    var_dump($tableName);
    die();
    $md5 = ...code...
    if (!empty($content = Cache::get($md5))) {
        return unserialize($content);
    }

I keep getting the error

Parse error: syntax error, unexpected '=', expecting ')'

in

if (!empty($content = Cache::get($md5))) {

And yes it recognises the class Cache and its function.

Can anyone guide me?

  • 写回答

2条回答 默认 最新

  • donglin7979 2019-04-17 09:42
    关注

    Prior to PHP 5.5, empty() function can only support strings.

    Any other input provided to it like: a function call e.g.

    if (empty(myfunction()) {
     // ...
    }
    

    would result parse error.

    As per documentation:

    Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

    Better way, get your $content variable first and then check if it is not empty.

    Rather than initialising it and checking its emptiness simultaneously.

    You can separate the if statement in two parts like this:

    if ($content = Cache::get($md5) && !empty($content)) {
     return unserialize($content);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程