Skip to content

Bug: jsonOrUnserialize() returns stdClass instead of array, crashes extrafields on supplier invoices #37227

@bryamzxz

Description

@bryamzxz

Bug

jsonOrUnserialize() in core/lib/functions.lib.php line 15710 calls json_decode($stringtodecode) without the second parameter, which returns a stdClass object instead of an associative array. This causes a fatal error when the result is later used as an array in extrafields.class.php.

Actual behavior

PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array 
in /var/www/html/core/class/extrafields.class.php on line 1345
Stack trace:
#0 /var/www/html/core/tpl/extrafields_list_search_input.tpl.php(84): ExtraFields->showInputField()
#1 /var/www/html/fourn/facture/list.php(1331): include('...')

Root cause

core/lib/functions.lib.php line 15710:

$result = json_decode($stringtodecode);  // Returns stdClass

Suggested fix

$result = json_decode($stringtodecode, true);  // Returns associative array

Dolibarr Version

22.0.4

Environment PHP

8.2

Environment Database

MariaDB 11.4

Steps to reproduce the behavior and expected behavior

Steps to reproduce

  1. Create a custom module that registers extrafields of type select or sellist on facture_fourn (supplier invoices)
  2. The extrafield options are stored as JSON in llx_extrafields.param
  3. Navigate to Billing → Supplier Invoices → List or Create

Expected behavior

The supplier invoice list and create form should render normally.

Attached files

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis is a bug (something does not work as expected)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions