2

Can anyone explain why these two pieces of code act differently and what I'm doing wrong:

print_r($user['first_signed_up_date']);
echo $user['first_signed_up_date']->milliseconds/1000;

Result:

MongoDB\BSON\UTCDateTime Object
(
    [milliseconds] => 1507976375000
)

1507976375

Second code:

// removed print_r / var_dump
echo $user['first_signed_up_date']->milliseconds/1000;

Result:

0

The only difference between first and second code is there's no print_r (var_dump has same result)

Chin Leung
  • 14,621
  • 3
  • 34
  • 58
caw
  • 65
  • 7
  • 3
    There are a few internal classes (such as DateTime) where properties are not exposed publicly until a var dump or export, or print_r because they aren't intended to be publicly accessible, but only through getter methods... it's a side-effect or var dump/export/print_r.... there is even a bug about this https://bugs.php.net/bug.php?id=49382 – Mark Baker Oct 20 '17 at 18:57

0 Answers0