PHP 5.3.10 vs PHP 5.5.3 syntax error unexpected '['

前端 未结 3 542
耶瑟儿~
耶瑟儿~ 2020-11-30 15:03

Is it possible that this PHP code line

if ($this->greatestId()[\"num_rows\"] > 0)

works in PHP 5.5 and returns an error in 5.3??

3条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 15:37

    Array dereferencing became available in PHP 5.4 That's why this doesn't work in PHP 5.3. So you have an extra step where you need to get the array value from your function call and then you can use it:

    $variable = $this->greatestId();
    if ($variable["num_rows"] > 0){
          // do stuff
    }
    

提交回复
热议问题