Bug #80895 [NEW]: Unexpected XML due to memory optimization in SOAP

From: Date: Mon, 22 Mar 2021 18:28:48 +0000
Subject: Bug #80895 [NEW]: Unexpected XML due to memory optimization in SOAP
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232919@lists.php.net to get a copy of this message
From:             vasilevrvv at gmail dot com
Operating system: Linux
PHP version:      8.0.3
Package:          SOAP related
Bug Type:         Bug
Bug description: Unexpected XML due to memory optimization in SOAP

Description:
------------
The problem is that when copying an array (not in pass by reference
case), ref elements are created in XML.

!!! This is due to memory optimization in PHP, since in fact the array
is copied only when it changes !!!

We get unexpected results:

The problem is solved by adding the line

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

as first cycle line.

At this point, the actual copying of the data took place. Reference was
broken.

After add we get correct result.

This is unexpected behavior. Behavior should not depend on the internal
"magic" of the PHP, it should be logical. Either always pass the same
data by reference, or if the data would have been explicitly passed by
reference (perfectably)

Test script:
---------------
private function test(Request\Shipment $shipment, array
$returnAddressee): array
{
    $items = [];
    foreach ($shipment->parcels as $k => $parcel) {
        $items[] = array(
        'receiverAddressee' =>
$this->createReceiverAddressee($shipment->consignee),
        'returnAddressee' => $returnAddressee
        );
    }
    
    return $items;
}

Unfortunately, I cannot give a complete script for testing, since it
depends on the WSDL service.

Expected result:
----------------
<item_list>
    <item service="CA">
        <receiverAddressee>
            <address postcode="13240" deliverypoint="La Solana"
country="RU"
                street="Calle Empedrada 45" />
        </receiverAddressee>
        <returnAddressee>
            <address postcode="123123" deliverypoint="Test"
country="EE"
street="Test 22" />
        </returnAddressee>
    </item>
    <item service="CA">
        <receiverAddressee>
            <address postcode="13240" deliverypoint="La Solana"
country="RU"
                street="Calle Empedrada 45" />
        </receiverAddressee>
        <returnAddressee>
            <address postcode="123123" deliverypoint="Test"
country="EE"
street="Test 22" />
        </returnAddressee>
    </item>
</item_list>

Actual result:
--------------
<item_list>
    <item service="CA">
        <receiverAddressee>
            <address postcode="13240" deliverypoint="La Solana"
country="RU"
                street="Calle Empedrada 45" />
        </receiverAddressee>
        <returnAddressee>
            <address postcode="123123" deliverypoint="Test"
country="EE"
street="Test 22"
                id="ref1" />
        </returnAddressee>
    </item>
    <item service="CA">
        <receiverAddressee>
            <address postcode="13240" deliverypoint="La Solana"
country="RU"
                street="Calle Empedrada 45" />
        </receiverAddressee>
        <returnAddressee>
            <address href="#ref1" />
        </returnAddressee>
    </item>
</item_list>

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80895&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80895&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80895&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80895&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80895&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80895&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80895&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80895&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80895&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80895&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80895&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80895&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80895&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80895&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80895&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80895&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80895&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80895&r=mysqlcfg


Thread (13 messages)

« previous php.bugs (#232919) next »