I have an object that looks like this:
Code:
[createdDatetime:Legacy\CdyneAddressReturns:private] => DateTime Object
(
[date] => -0001-11-30 00:00:00
[timezone_type] => 3
[timezone] => America/Chicago
)
At least, that's what it looks like it I print_r the object. However, if I don't run a print_r or a var_dump on the object first, it appears to be empty, or at least I can't access it.
For instance, when I run
PHP Code:
foreach($currentRecord as $key => $value)
{
$dateVar = $value->getCreatedDatetime();
$createdDate = $dateVar->date;
echo "createDate is " . $createdDate . "<br/>";
}
Then $createDate is empty, and I get an undefined property error (Notice: Undefined property: DateTime::$date).
However, if I simply stick a print_r at the top..
PHP Code:
foreach($currentRecord as $key => $value)
{
$value->getCreatedDatetime();
$dateVar = $value->getCreatedDatetime();
$createdDate = $dateVar->date;
echo "createDate is " . $createdDate . "<br/>";
}
Then everything appears to work fine, and I get...
createDate is -0001-11-30 00:00:00
I've never run into a problem like this before where my program behaved differently based simply on whether or not I printed something out in the middle of it. Any idea what's going on here?