dqstti8945 2016-05-20 11:22
浏览 67
已采纳

对象属性未显示

I have a function on a php page that is intended to grab the creation date/time of video files using getid3. I thought everything had been working fine and was ready to put this version to bed when I was (of course) running everything one more time to make sure and ended up with an issue I just can't seem to figure out.

The relevant bit of code is this:

$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($file);
if ($ThisFileInfo["quicktime"]["moov"]["subatoms"][0]["creation_time_unix"]){
    $createdate = new DateTime("@".strval($ThisFileInfo["quicktime"]["moov"]["subatoms"][0]["creation_time_unix"]));
}
else {
    $createdate = new DateTime("@".strval($ThisFileInfo["quicktime"]["moov"]["subatoms"][0]["modify_time_unix"]));
}
$createdate->setTimeZone(new DateTimeZone('America/New_York'));
//var_dump($createdate);
$createdate = $createdate->date;

When I process a file using this portion I get an error stating Notice: Undefined property: DateTime::$date in … line 179(file path removed by me). However, I know that this isn't the case because if I uncomment the var_dump line listed above I get the output object(DateTime)#3 (3) { ["date"]=> string(26) "2016-01-24 15:20:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "America/New_York" }.

It certainly looks to me like the DateTime object $createdate has a property called $date, so I'm not sure what's going on, though I'm assuming it's something in my syntax. Can someone help me to sort this out?

  • 写回答

1条回答 默认 最新

  • dqys98341 2016-05-20 11:37
    关注

    If you're not sure which variables are accessible from your current scope of an object, you can use get_class_vars().

    Using it on a DateTime object returns an empty array:

    var_dump(get_class_vars(get_class($datetimeobj)));
    

    ...which means the $date property is private one. Of course, you can access the string representation of the DateTime object with the date_format() method:

    $dateString = date_format($dateTimeObj, 'Y-m-d H:i:s');
    

    You can read more on the format syntax in the "date" manual.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么