xiaohutai / jsonapi

[Bolt Extension] JSON API for Bolt CMS

Home Page:https://market.bolt.cm/view/bolt/jsonapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception in src/Action/FetchAction.php file on PHP 7.2

barthicus opened this issue Β· comments

Bolt is throwing exception on PHP 7.2 when single resource is requested.

eg. my-site.local/json/pages/contact

image

This is known problem when PHP is upgraded do version 7.2.
More info: https://wiki.php.net/rfc/counting_non_countables

I fixed it locally by changing one condition in src/Action/FetchAction.php (line 53).

From:
if (! $results || count($results) === 0) {

To:
if (! $results || (is_array($results) && count($results) === 0)) {

I'm not daily PHP coder and I'm not sure if it is the best solution. Please correct me if it s not.
The most important is fact that now it works on my nginx + PHP 7.2 setup.
Have a nice day!

PS: This is my first issue sent on github :)

I'm not daily PHP coder and I'm not sure if it is the best solution.

LGTM πŸ‘

PS: This is my first issue sent on github :)

Would you like to follow it up with your first PR to fix your first issue? We'd be happy to help make it happen 😸

Would you like to follow it up with your first PR to fix your first issue? We'd be happy to help make it happen 😸

I will try πŸ˜„

I've made a pull request: #76
I was struggling because need to read some tuts about how to do it.
The biggest problem was to find a way to submit PR from my repo to this repo. I hope it's ok finally.
Next time will try to do this by command line instead of clicking here.
There is some history mess with my commits on my forked repo.
I was practicing and deleting some branches and didn't know it will be shown here. Sorry about that.

Zero stress, you got it right in the end and I'll let @xiaohutai chime in now but everything looks good to me πŸ‘ Thank you!

@barthicus Great! Thanks for your contribution! πŸ˜„

Not sure if a ! empty( ... ) would've sufficed.

Not sure if a ! empty( ... ) would've sufficed.

Not safely, as 'koala' and 42 are both "not empty", but neither are arrays or implement Countable.