Skip to content

Commit

Permalink
Fixed issue #12997: PHP warning "mktime() expects" when calling surve…
Browse files Browse the repository at this point in the history
…y logic file
  • Loading branch information
Shnoulle committed Dec 9, 2017
1 parent 03260bd commit 146d960
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions application/helpers/expressions/em_core_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2558,7 +2558,8 @@ function exprmgr_log($args)
}
/**
* Get Unix timestamp for a date : false if parameters is invalid.
* PHP 5.3.3 send E_STRICT notice without param, then replace by time if needed
* Get default value for unset (or null) value
* E_NOTICE if arguments are not integer (debug>0), then return test it before
* @param int $hour
* @param int $minute
* @param int $second
Expand All @@ -2567,25 +2568,22 @@ function exprmgr_log($args)
* @param int $year
* @return int|boolean
*/
function exprmgr_mktime($hour = null, $minute = null, $second = null, $month = null, $day = null, $year = null)
function exprmgr_mktime($hour=null,$minute=null,$second=null,$month=null,$day=null,$year=null)
{
$iNumArg = count(array_filter(array($hour, $minute, $second, $month, $day, $year), create_function('$a', 'return $a !== null;')));
switch ($iNumArg) {
case 0:
return time();
case 1:
return mktime($hour);
case 2:
return mktime($hour, $minute);
case 3:
return mktime($hour, $minute, $second);
case 4:
return mktime($hour, $minute, $second, $month);
case 5:
return mktime($hour, $minute, $second, $month, $day);
default:
return mktime($hour, $minute, $second, $month, $day, $year);
}
$hour = isset($hour) ? $hour : date("H");

This comment has been minimized.

Copy link
@olleharstedt

olleharstedt Dec 11, 2017

Collaborator

$hour will always be set, since it's an argument. Maybe you meant is_null?

This comment has been minimized.

Copy link
@olleharstedt

olleharstedt Dec 11, 2017

Collaborator

Oh, nevermind, isset also checks for null. Sorry!

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Dec 11, 2017

Author Collaborator

You're right :). Another idea is to use array_merge, but this one seems clearer enough.

This comment has been minimized.

Copy link
@LouisGac

LouisGac Dec 11, 2017

Contributor

empty() > all

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Dec 11, 2017

Author Collaborator

Not empty : because is user send "" or 0 : we need to keep it. is_nulll maybe

This comment has been minimized.

Copy link
@LouisGac

LouisGac Dec 11, 2017

Contributor

ok, then... we need... empty() ⛄
http://php.net/manual/en/function.empty.php

Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE.

The following things are considered to be empty:

"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
$var; (a variable declared, but without a value)

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Dec 11, 2017

Author Collaborator

No, we DON'T need empty, we need ONLY is_null (or isset).

Example : {mktime(NumericQuestion.NAOK)} must return false, empty string if user didn't enter value in NumericQuestion, for easiest EM usage :).

This comment has been minimized.

Copy link
@LouisGac

LouisGac Dec 11, 2017

Contributor

ok ok...
that reminds me... Sliders (touched vs not touched vs NULL vs 0 vs "" etc)
maybe that is the sign we should have a specific validation rule for those kind of cases

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Dec 11, 2017

Author Collaborator

:) .

I think, it's this : in PHP session, for SGQA : ($_SESSION['survey_'.$sid][$sgq])

  • value is null : then user don't see it before (for example : new page or hidden by expression)
  • value is "" : user see it but didn't answer (or answer an empty string ?)
  • value is 0 : user see it and enter 0

But : we have null for datetime and decimal even if user see it after reloading (with token for example) sur to DB. I think, to be confirmed.

$minute = isset($minute) ? $minute : date("i");
$second = isset($second) ? $second : date("s");
$month = isset($month) ? $month : date("n");
$day = isset($day) ? $day : date("j");
$year = isset($year) ? $year : date("Y");
$hour = isset($hour) ? $hour : date("H");
$iInvalidArg = count(array_filter(array($hour,$minute,$second,$month,$day,$year), function($timeValue) {
return strval($timeValue) !== strval(intval($timeValue));
}));
if($iInvalidArg) {
return false;
}
return mktime($hour,$minute,$second,$month,$day,$year);
}

/**
Expand Down

0 comments on commit 146d960

Please sign in to comment.