John Davidson

arrays - php create several objects within object

0 comments
Message:


I am trying to make a soap request and it needs to have this structure


$requestBody=new sendDataExtraccionRequest(new sendDataExtraccionSubterranea("18-09-2020","00:02:01",1234567891,12345678.12,12345678.12),
new sendDataExtraccionSubterranea("18-09-2020","00:03:01",1234567891,12345678.12,12345678.12));

thought that by creating an array with each object and then cast it should do, but getting an error on the soap call that the date field is missing


$array_datos[] = new sendDataExtraccionSubterranea("03-02-2021","00:02:01",1234567891,12345678.12,12345678.12);
$array_datos[] = new sendDataExtraccionSubterranea("03-02-2021","00:03:01",1234567891,12345678.12,12345678.12);

$requestBody=new sendDataExtraccionRequest( (object)$array_datos );

Also tried a solution that involved json encoding and decoding the array, but same error


Any hint on how to achieve it?
Thanks



My Answer:
You can achieve the desired structure by creating an array of objects and passing it to the constructor of `sendDataExtraccionRequest`. Here's an example of how you can do it:

php
// Create an array of objects
$array_datos = array(
new sendDataExtraccionSubterranea("03-02-2021","00:02:01",1234567891,12345678.12,12345678.12),
new sendDataExtraccionSubterranea("03-02-2021","00:03:01",1234567891,12345678.12,12345678.12)
);

// Pass the array of objects to the constructor of sendDataExtraccionRequest
$requestBody = new sendDataExtraccionRequest($array_datos);


This way, each object in the array will be passed as a separate argument to the constructor of `sendDataExtraccionRequest`, and the structure of the SOAP request should be correct.

Rate this post

4 of 5 based on 2718 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us