Just like core in #2853503: Remove all assert('string') calls from Drupal core because deprecated in PHP 7.2, the JSON API module will need to update its assert() calls.

CommentFileSizeAuthor
#2 2920892-2.patch981 byteswim leers

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new981 bytes
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Fixed

This is trivial enough that I can commit it right away.

I'm surprised that there's only one assert() :)

wim leers’s picture

Issue tags: +PHP 7.2
e0ipso’s picture

@Wim Leers, did you commit that in the end? I don't see the commit notification in the comments.

Does this require a PHP version dependency? In other words, does asserting via an expression (and not a function) work with all php5 versions supported by D8?

wim leers’s picture

Yes: http://cgit.drupalcode.org/jsonapi/commit/?id=4c13013.

d.o commit messages in issues appear to be broken.

Does this require a PHP version dependency? In other words, does asserting via an expression (and not a function) work with all php5 versions supported by D8?

Yes, it works on all versions. The difference is that on PHP 5, the logic in the assert() call will now be executed 100% of the time, instead of only when assert()s are enabled in php.ini. This is a decision made by the PHP team.

e0ipso’s picture

The difference is that on PHP 5, the logic in the assert() call will now be executed 100% of the time, instead of only when assert()s are enabled in php.ini.

Does this have a performance impact on production servers running PHP5?

wim leers’s picture

Yes, since the assertions will now run 100% of the time.

e0ipso’s picture

One of the reasons to add these as assertions was that they'd only run during development. If that is not true anymore, then we should come up with an alternative approach before tagging the next release.

wim leers’s picture

I agree, and I hadn't thought of that when I committed this, it seems obvious now. It was late on Friday. This change was necessary in any case, for PHP 7.2 compatibility. 7.2.0 is being released on November 30, so this change was necessary in the next JSON API release anyway.

It really sucks that the PHP team is forcing this :(

I was opening a new issue for that, but then I realized … that the validation is only happening if the justinrainbow/json-schema dev dependency is installed. Which won't be the case on production sites anyway.

So perhaps the thing is that this should not use assert() at all, it should run always when the dev dependency is installed?

  • Wim Leers committed 4c13013 on 8.x-1.x
    Issue #2920892 by Wim Leers: Remove all assert('string') calls from JSON...
e0ipso’s picture

I don't think we can ensure that the presence of that popular PHP library means development mode. It could have been added by a different contrib.

wim leers’s picture

You’re right.

Let’s create a new issue then, to only run the assert if assertions are enabled. /me waves fist at PHP team.

Let’s make sure to add a todo to remove that condition when D8 only supports PHP 7.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.