PHP 8 error when rendering citations for reference that have contributor with author role

Created on 20 September 2022, about 2 years ago
Updated 7 May 2024, 7 months ago

Problem/Motivation

After updating to PHP 8.1, we get errors when citations are rendered for any reference that doesn't have at least one contributor with the 'author' role.

Note we're using the latest version of citeproc-php from seboettg.

TypeError: count(): Argument #1 ($value) must be of type Countable|array, stdClass given in count() (line 256 of /var/www/html/princeton/vendor/seboettg/citeproc-php/src/Rendering/Name/Name.php).

The problem is actually in the bibcite entity normalizer. The normalized data for contributors is first set up such that contributors are stored in an associative array keyed by contributor type (e.g. author, editor, etc). This is assigned to the key "author" in the normalized data array. A separate process then iterates thru this list of contributor types and sets a top level array key for each contributor type on the normalized data array. For "author", this second process would overwrite the original "author" key on the normalized array.

The problem is if there is no contributor with the "author" type, then that second process never happens, and the original "author" key remains with the original 2d array of all the contributors. Citeproc doesn't expect this - it assumes the data in "author" key will be a non-associative array of the authors.

Steps to reproduce

Use PHP 8.0 or 8.1, use latest version of citeproc-php from seboettg, add a reference that has an "editor" contributor but no "author" contributor, and try to view the reference rendered as a citation (you can do this by viewing the detail page of the contributor).

Proposed resolution

In the custom CSL normalizer, if there's no author roles present, then clear out the original "author" value in the normalized data array so it doesn't mess up citeproc renderer.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024