When using Services views runing on php 7.1 node title and text fields only return the first character, text area are empty.
I am using the plain text formatter for all text fields and text area's.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | services_views-php-7_1-fixes-2910966-22.patch | 792 bytes | scott.whittaker |
| #18 | services_views-php-7_1-fixes-2910966-18.patch | 648 bytes | dmitrii |
| #10 | Screenshot_2017-12-01_14-40-00.png | 24.84 KB | generalredneck |
| #8 | services_views-php-7_1-fixes-2910966-8.patch | 650 bytes | emerham |
| #7 | Screenshot from 2017-10-04 08-12-04.png | 141.77 KB | emerham |
Comments
Comment #2
emerham commentedIt does still work in 7.0 and 5.6.
Turning on drupal logging and loaded an view I am greeted with
Notice: Uninitialized string offset: 0 in services_views_execute_view() (line 258 of /sites/all/modules/services_views/services_views.resource.inc).
The call is on this section of code
so its on
Comment #3
emerham commentedMy guess is it has something to do with how element ordering is assign in 7.1 that was different in previous versions when assigning by reference. http://php.net/manual/en/migration71.incompatible.php
I will keep digging and hopefully get it working as I want to move my code base to PHP 7.1 and we rely on this module.
Comment #4
emerham commentedSo the issue is how PHP handles the empty index operators. PHP Reference and when this is done the string is silently converted to an array of size 1 PHP 7.1 Array Update.
The fix ended up being simple, just needed to change the empty initiator from '' to array().
Comment #5
emerham commentedComment #6
pcambraI think this is a duplicate of https://www.drupal.org/node/2718537
Comment #7
emerham commentedClose, but the issue is still with how array's are variables are created and when the variable is converted to an array from a string silently in PHP 7.1.1+

Before applying my patch ( and the linked issue) this is what my service returns:
After applying my patch this is what the service should be returning:

Comment #8
emerham commentedSo I had a regression where empty strings were returning as empty arrays. By typecasting the string as an array I am able to get this working like it should on latest version of PHP 7 as well as PHP 5.
Comment #9
prakashsingh commentedPerfect. The patch at #8 works for me.
Thanks
Prakash
Comment #10
generalredneck@emerham,
I'm not able to reproduce this. I am running PHP 7.1.12-1+ubuntu16.04.1+deb.sury.org+1 under Drupal VM. Would you mind exporting your view?
I've tested with the following without your patch on the latest Dev as well as before #2718537: Notice: Uninitialized string offset: 0 in services_views_execute_view() was committed and I'm not able to reproduce this issue. Here's my view... and here is my content type. Many Text has multiple carnality.
Comment #11
generalredneckOk I managed to stumble across the problem. This is yet another difference between the "Services View Resource" using a services views display type and just using the straight up views endpoint. I should have noticed when you had Capital letters in your labels... My bad... Let me do some more testing.
Comment #12
generalredneck@emerham,
I made a slight change. I like the readability of
$output[$index]->$target_key[] = '';vs
$output[$index]->$target_key = (array) '';I actually had to do a test on the 2nd to see that casting a string to an array actually made an array with the single string element in it... which goes against my intuition in C based laguages where strings are an array of chars...
Example I expected this to be equivalent to
$output[$index]->$target_key = array();because it was an empty string. Instead we get an array with one element: '' in it. Likewise if you do$output[$index]->$target_key = (array) "BLAH";I expected to see an array of 4 elements 'B', 'L', 'A', and 'H'... not an array with one element "BLAH" in it...I'm still giving you full credit for the fix though as it was your initial work that found it...
This is all necessary because down in the output assignment, we always assign the output to
$obj[$idx]instead of checking to see if the cardinality is 1. The fix to the notice before in #2718537: Notice: Uninitialized string offset: 0 in services_views_execute_view() was covering this up really by checking if this was an array... when in theory, we should always be dealing with arrays of values...Comment #15
WayneDyck commentedWhat is the process for getting this commit pushed out as an update to the stable branch?
Comment #16
dmitrii commentednote:
$output[$index]->$target_key[] = '';breaks sites on PHP 5.6 with messageFatal error: Cannot use [] for reading in services_views/services_views.resource.incComment #17
zuhair_akMaybe we should change it to
$output[$index]->$target_key = array();for it to work?Comment #18
dmitrii commentedservices_views-php-7_1-fixes-2910966-18.patch fixes issue with PHP 5.6 and works with PHP 7.1
Comment #19
dmitrii commented@zuhair_ak It looks like we need value in the array to use same logic for multivalue and singlevalue fields.
It converted to a single value later at line 257
Comment #20
liam morland@#17: To do the same thing, it would have to be like this:
I think this is more readable than the other options.
Comment #21
liam morlandI have made child ticket #3032803: Fatal error: Cannot use [] for reading to continue this.
Comment #22
scott.whittaker commentedPrevious patch no longer applies, here's an update.
Comment #23
scott.whittaker commented