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 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目