Crell / ApiProblem

A simple implementation of the api-problem specification. Includes PSR-15 support.
MIT License
239 stars 21 forks source link

Using PHP empty function strips out properties in the response. #33

Closed nyamsprod closed 3 years ago

nyamsprod commented 3 years ago

Code to reproduce:

<?php

$problem = new ApiProblem('0');
echo json_encode($problem, JSON_PRETTY_PRINT), PHP_EOL;

Expected:

{
    "title": "0",
    "type": "about:blank"
}

Returned:

{
    "type": "about:blank"
}

The title property is missing because it is evaluated via PHP empty function. This should be replace by a strict comparison against empty string '' !==. when needed