Skip to content

type error in jsonSerialize functions in many objects #363

@kaeverens

Description

@kaeverens

SDK you're using (please complete the following information):

  • Version 7.0.1

Describe the bug
in the method jsonSerialize, $json is initialised as a plain array []

4 lines later, you try to set $json->Organisations on it. https://github.com/XeroAPI/xero-php-oauth2/blob/master/lib/Models/Accounting/Organisations.php#L311

this fails because [] is not an object. it's an array.

sample error message:

[31-Jul-2024 13:43:16 UTC] PHP Fatal error:  Uncaught Error: Attempt to assign property "Organisations" on array in /home/crm/www/vendor/xeroapi/xero-php-oauth2/lib/Models/Accounting/Organisations.php:311
Stack trace:
#0 [internal function]: XeroAPI\XeroPHP\Models\Accounting\Organisations->jsonSerialize()
#1 /home/crm/www/php/api.php(370): json_encode(Array, 2097152)
#2 {main}
  thrown in /home/crm/www/vendor/xeroapi/xero-php-oauth2/lib/Models/Accounting/Organisations.php on line 311

To Reproduce
Steps to reproduce the behavior:

  1. do something which causes jsonSerialize() to run.

Expected behavior
I expect it to just create the expected JSON and return it.

Additional context
if you change $json->Organisations to $json['Organisations'] that fixes the immediate problem, but you appear to have made the exact same mistake in other files as well (see Contacts.php in the same directory, line 344).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions