Issue Bug Closed

#81019Query Builder: Error when ordering by DateTime fields

Radu Mogos 04/26/17, 09:55 updated 10/02/18, 11:01

Description

Hello

I have an Extbase model with a DateTime “crdate” field, defined like this in the model.

/**
 * crdate
 *
 * @var \DateTime
 */
protected $crdate;

In it’s repo I’m just trying to fetch all its models in a custom function, all this function does is return all the objects and sort them by the crdate field:

    public function getLatestJobs($limit = 0) {
        $query = $this->createQuery();
        $query->getQuerySettings()->setRespectStoragePage(FALSE);
        if ($limit) {
            $query->setLimit($limit);
        }
        $query->setOrderings(array('crdate' => QueryInterface::ORDER_DESCENDING));

        return $query->execute();
    }

This generates a TYPO3 exception in the frontend, as the compiled code does an htmlspecialchars call when fetching the date.
This is the error I get: “#1476107295: PHP Warning: htmlspecialchars() expects parameter 1 to be string, object given”, and the compiled code which generates the error looks like this:

$arguments98 = array();
$arguments98['date'] = NULL;
$arguments98['format'] = '';
$arguments98['base'] = NULL;
$arguments98['format'] = 'Y-m-d';
$array100 = array (
);$arguments98['date'] = htmlspecialchars($renderingContext->getVariableProvider()->getByPath('job.crdate', $array100), ENT_QUOTES);

I’m assuming that $renderingContext->getVariableProvider()->getByPath(‘job.crdate’, $array100) returns a DateTime object while htmlspecialchars deals only with strings, obviously.

Reviews 2