Skip to content

Changed the method of comparison for creation date in DF_Models' save() method

Robert Sinton requested to merge patch/timestamp_comparison into master

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

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)

Merge request reports