duanqilupinf67040 2013-05-07 02:27
浏览 13

变量空白直到倾倒

Variable $now won't display unless it is dumped. It's populated. It doesn't display the "now is empty" string at all. It won't display what is inside $now unless it is var_dump or var_exported.

$ipData = json_decode( $ttt, true);
$now="";
if ($ipData['timezone']) {
    $tz = new DateTimeZone( $ipData['timezone']);
    $now = new DateTime( 'now', $tz); // DateTime object corellated to user's timezone
} else {
   // we can't determine a timezone - do something else...
}



if($now==""){echo "now is empty";}

echo "<br />
<br />
".$now->timezone.$now->date;
var_dump($now);

}

if(isset($now)){echo "It is set.";} It's definitely set, though I set it to "" before I actually called it, so no matter what it was initialized.

Even removing the $now=""; shows that it is initialized. var_dump($now); echos this:

object(DateTime)#30 (3) { ["date"]=> string(19) "2013-05-06 22:52:29" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "America/New_York" } After var_dump $now->timezone is equal to America/New_York

  • 写回答

2条回答 默认 最新

  • douwei1408 2013-05-07 02:31
    关注

    Make sure you are actually entering that IF condition. You can try isset($var) to see if the var was initialized, or empty($var) to see if it has something inside. [Instead of =="")

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类