I have the same issue described in https://www.drupal.org/project/services_views/issues/2198951 using the latest dev version and PHP 7.1.
This is a regression bug from the PHP 7.1 fixes done in https://www.drupal.org/project/services_views/issues/2910966.

In my case I needed empty string instead of array, I did a small hack to get it.

  --- a/services_views.resource.inc
+++ b/services_views.resource.inc
@@ -178,13 +178,13 @@ function services_views_execute_view($view_info, $view = NULL, $display_id = NUL
         // Create helper variables.
         $output[$index]->$target_key = array();
         if ($field->field_info['cardinality'] == 1) {
-          $output[$index]->$target_key[] = '';
+          $output[$index]->$target_key = '';
         }
         $obj = &$output[$index]->$target_key;
         $format = ($field->options['type'] == 'services') ? 'raw' : 'rendered';
 
         foreach ($row->$f_key as $idx => $res) {
-
+          $obj = array();
           if (isset($res[$format])) {
             $data = $res[$format];

Is there are any other better way to get this done?

Comments

zuhair_ak created an issue. See original summary.

zuhair_ak’s picture

StatusFileSize
new804 bytes

Hacky way to get empty string instead of array.

dmitrii’s picture

Status: Active » Needs review
StatusFileSize
new1.27 KB

@zhhair_ak we cannot user $obj = array(); since it overwrites multi value fields.
Moved the cardinality check of a field outside of the foreach to count on empty fields.
See patch.

zuhair_ak’s picture

@dmitrii You are correct, it will not display mulitvalue fields, in my specific case I needed empty string if there is no value, so I just changed my patch to check for multivalue fields -

  if ($idx == 0) {
    $obj = [];
  }

Thanks for the patch.

lawxen’s picture

Status: Needs review » Needs work

#3 can't be applied to newest services_views, if I write the code by hand through the patch, don't work either

lawxen’s picture

Status: Needs work » Needs review
StatusFileSize
new845 bytes
roman_l’s picture

#6 is the way to go to solve the empty array issue (annoying when we expect a string).

Thanks @lawxen !

rajeev_drupal’s picture

Assigned: Unassigned » rajeev_drupal

#6 worked for me. Thanks

rajeev_drupal’s picture

Assigned: rajeev_drupal » Unassigned
WayneDyck’s picture

I can confirm #6 worked for me as well. I originally opened issue #3096315 because of the empty arrays being generated where a empty string used to be.

Also, my opinion, however, I don't think we should be making changes to accommodate PHP 5.6 at this point. Support for PHP 5.6 ended on December 31, 2018.

jeremyvdm’s picture

Hi I just want to report that I have got this issues with the newest version 1.4 had to go back to the 1.2 because I didn't have this issue with the 1.2 and unfortunately the patch of #6 didn't work I kept having skipped patches

alison’s picture

Status: Needs review » Reviewed & tested by the community

#6 worked great to fix the empty array problem for us!! Thank you!!

PHP 7.2.28
Core 7.72
services_views 7.x-1.4

(I realize it didn't work for one person, but it did work for 4 of us... so I'm marking RTBC for now -- obviously, feel free to overrule me :) )

-------
@jeremyvdm - Are you saying that the patch on #6 didn't apply to version 1.2, or it didn't apply even after you updated to 1.4?
(Also, did you also see the warning on the project page about upgrading to 1.3? -- did you go right from 1.2 to 1.4, and did you update your endpoints first?)

  • generalredneck committed 5e14cdf on 7.x-1.x authored by lawxen
    Issue #2997446 by zuhair_ak, lawxen, dmitrii: For empty or no values,...
generalredneck’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all for all the testing and work through the multiple issues.

Status: Fixed » Closed (fixed)

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