Is this $lastcron variable being evaluated correcty?

Viewed 41

Please refer to this PHP code: https://github.com/jleyva/moodle-block_configurablereports/blob/MOODLE_36_STABLE/block_configurable_reports.php#L182

Line 182 uses the $DB object to get data from a sql database and then puts the result in the $lastcron variable.

The next line evaluates the $lastcron variable like this:

    if (!$lastcron and ($lastcron + $this->cron < time()) )

Please explain this code to me!

Should that if() statement use !$lastcron or $lastcron at the beginning of the if() statement? In other words, should it be:

      if (!$lastcron and ($lastcron + $this->cron < time()) )

or

      if ($lastcron and ($lastcron + $this->cron < time()) )
1 Answers

You are right, looks like a bug to me.

$DB->get_field() returns false if the record doesn't exist or a value if it does exist.

In this case an integer value for lastcron

It probably should be an or

if (!$lastcron || ($lastcron + $this->cron < time()) )
Related