kartik-v / yii2-date-range

A Date Range Picker for Bootstrap useful for reports and filtering.
http://demos.krajee.com/date-range
Other
93 stars 81 forks source link

Correct code for PHP 5.5 #75

Closed conick closed 8 years ago

conick commented 8 years ago

After last update I've got an error:

Can't use method return value in write context

1. in /projects/php/project1/vendor/kartik-v/yii2-date-range/DateRangePicker.php at line 480
471472473474475476477478479480481482483484485486487488489
    /**
     * Generates and returns the client script on date range change, when the start and end attributes are set
     *
     * @param string $type whether `start` or `end`
     *
     * @return string
     */
    protected function getRangeJs($type = '')
    {
        if (empty($this->getRangeAttr($type))) {
            return '';
        }
        $options = $this->getInputOpts($type);
        $input = "jQuery('#" . $this->options['id'] . "')";
        return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#" . $options['id'] .
        "').val(v).trigger('change');";
    }

    /**

The problem due to the fact that since php 5.5, function is invalid value for empty() function:

Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

Please change getRangeJs() in DateRangePicker.php

From:

protected function getRangeJs($type = '')
{
    if (empty($this->getRangeAttr($type))) {
        return '';
    }
    $options = $this->getInputOpts($type);
    $input = "jQuery('#" . $this->options['id'] . "')";
    return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#" . $options['id'] .
    "').val(v).trigger('change');";
}

To:

protected function getRangeJs($type = '')
{
    $rangeAttr = $this->getRangeAttr($type);
    if (empty($rangeAttr)) {
        return '';
    }
    $options = $this->getInputOpts($type);
    $input = "jQuery('#" . $this->options['id'] . "')";
    return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#" . $options['id'] .
    "').val(v).trigger('change');";
}