Bug #80895 [Csd->Asn]: Unexpected XML due to memory optimization in SOAP

From: Date: Wed, 24 Mar 2021 14:33:03 +0000
Subject: Bug #80895 [Csd->Asn]: Unexpected XML due to memory optimization in SOAP
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232972@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80895&edit=1

 ID:                 80895
 User updated by:    vasilevrvv at gmail dot com
 Reported by:        vasilevrvv at gmail dot com
 Summary:             Unexpected XML due to memory optimization in SOAP
-Status:             Closed
+Status:             Assigned
 Type:               Bug
 Package:            SOAP related
 Operating System:   Linux
 PHP Version:        8.0.3
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

I think this is not obvious behavior. To avoid references - I have to clone the object in the code.
Maybe it's better to change this logic?


Previous Comments:
------------------------------------------------------------------------
[2021-03-24 14:26:22] cmb@php.net

Well, apparently ext/soap indeed not only encodes references as
multi-reference values, but also zvals with refcount > 1.  The
latter doesn't look right to me for arrays, because these are
value types in PHP, but not necessarily in other languages.

------------------------------------------------------------------------
[2021-03-24 13:57:59] vasilevrvv at gmail dot com

Hmm, in php5, the behavior is generally differen ti need to research

------------------------------------------------------------------------
[2021-03-24 13:31:56] vasilevrvv at gmail dot com

each pass of the foreach is the same zval, before trying to change it. and the soap library takes
this as a reference, but it is not a reference.

------------------------------------------------------------------------
[2021-03-24 13:14:23] vasilevrvv at gmail dot com

For example, let's change not the address, but another variable, this also helped. And add call
xdebug_debug_zval before and after call:

xdebug_debug_zval('returnAddressee');
$returnAddressee['person_name'] = $returnAddressee['person_name'];
xdebug_debug_zval('returnAddressee');

Before:

(refcount=4, is_ref=0)
array (size=4)
  'person_name' => (refcount=1, is_ref=0)string ',,,,,,

Here refcount=4

Call:

$returnAddressee['person_name'] = $returnAddressee['person_name'];

After

(refcount=1, is_ref=0)
array (size=4)
  'person_name' => (refcount=2, is_ref=0)string '.....

Here refcount=1

When the array changes, it becomes another array, this is what causes the problem

------------------------------------------------------------------------
[2021-03-24 12:55:31] vasilevrvv at gmail dot com

No, $returnAddressee do not contain references. Its just json_decode() result.

Inside php since version 7.x, arrays are always stored by links, they are copied only when you try
to change them. this is internal logic that is not visible to the end programmer

The problem is solved by the fact that I just copy the same value into it. PHP inside takes this as
an attempt to change and then copies the array in memory.

Fix code:

$returnAddressee['address'] = $returnAddressee['address'];

Helps not only it, but any change in the array, of any other field.

I think that after the release of these optimizations in PHP, this was simply not taken into account
in the SOAP module

var_dump:

array(4) {
  ["person_name"]=>
  string(29) "NAME"
  ["phone"]=>
  string(11) "+372123123123"
  ["email"]=>
  string(16) "sales@testcompany.com"
  ["address"]=>
  array(4) {
    ["postcode"]=>
    string(5) "12312"
    ["deliverypoint"]=>
    string(5) "Narva"
    ["country"]=>
    string(2) "EE"
    ["street"]=>
    string(13) "Test 21"
  }
}

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=80895


--
Edit this bug report at https://bugs.php.net/bug.php?id=80895&edit=1


Thread (13 messages)

« previous php.bugs (#232972) next »