Changed the method of comparison for creation date in DF_Models' save() method
In a project with E_NOTICE errors included, I noticed that my API response had this notice warning in it:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: A non well formed numeric value encountered</p>
<p>Filename: core/DF_Model.php</p>
<p>Line Number: 3497</p>
</div>
Relevant code is:
// If created is provided && is a timestamp then convert it back to a date string
if(!empty($data['created']) && (int)$data['created'] == $data['created']){
$data['created'] = DATE("Y-m-d H:i:s", $data['created']);
}
Not certain, but I think the ==
test is resulting in the second operand being implicitly cast to integer in order to compare it to the first one.
The test then always passes, so the DATE()
call is always made, even if $data['created'
is in fact a date string. That's what raises the Notice.
What I did
- Changed the way that we check to see if $data['created'] is an integer
- Logic is from: https://stackoverflow.com/questions/6416763/checking-if-a-variable-is-an-integer-in-php
- (I first used a
(string)
cast on both sides of an===
, which is basically their second option, but the first one seemed better.) - "0" case is OK to ignore because we were already using a
! empty()
check
Implications
I'm just gonna say "Unknown"
Setup
None
How to test
- Test in a project that has E_NOTICE errors turned on
- Observe that a Notice is not raised when saving, with this change in place.
Task: (none)