Skip to content

Convert array columns inside rows to PHP arrays#19

Merged
jdatcmd merged 1 commit into
php-compat-cifrom
row-conversion
Jul 6, 2026
Merged

Convert array columns inside rows to PHP arrays#19
jdatcmd merged 1 commit into
php-compat-cifrom
row-conversion

Conversation

@jdatcmd

@jdatcmd jdatcmd commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #18 (which stacks on #17); retarget as they merge. Full suite green on PG 11–18 (+ jsonb_plphp) in the pre-CI sweep.

The last big ergonomic wart: an array-typed column crossed into PHP as its literal text form ({a,b}) everywhere a whole row converts — $_TD['new']/['old'] in triggers, rows from spi_fetch_row/spi_fetchrow/spi_each, and composite arguments' fields. Column values now route through the same conversion arguments already get:

CREATE FUNCTION tag_trigger() RETURNS trigger LANGUAGE plphp AS $$
    $_TD['new']['tags'][] = 'audited';    -- it's a real PHP array
    return 'MODIFY';                      -- and converts back on write
$$;

The reverse path already rendered PHP arrays into array literals (via the #13 rewrite), so read-modify-write round trips work — the new tests pin SPI rows, cursor rows, the trigger append+MODIFY round trip, and composite argument fields.

Matches PL/Perl's recursive row conversion. Behavior change (CHANGELOG'd): code that string-parsed the literal form should use the array directly. Composite-typed columns inside rows still arrive as text — converting those needs a record parser, a possible follow-up.

🤖 Generated with Claude Code

An array-typed column used to cross into PHP as its literal text form
("{a,b}") everywhere a whole row converts: $_TD['new']/['old'] in
triggers, rows from spi_fetch_row/spi_fetchrow/spi_each, and the
fields of composite-type arguments.  Route those column values through
the same conversion arguments already get, so they arrive as real PHP
arrays -- and, since the reverse path (plphp_zval_get_cstring with
do_array) already renders PHP arrays back into array literals,
assigning an array works too, e.g. modifying $_TD['new']['tags']
before returning MODIFY.

This matches PL/Perl, which converts row fields recursively.  It is a
behavior change for code that string-parsed the literal form, noted in
the CHANGELOG.  Composite-typed columns inside rows still arrive as
text (converting those needs a record parser; possible follow-up).

New cases in the arrays test cover SPI rows, cursor rows, triggers
(read + append + MODIFY round trip), and composite argument fields.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jdatcmd
jdatcmd merged commit 50534f4 into php-compat-ci Jul 6, 2026
11 checks passed
@jdatcmd
jdatcmd deleted the row-conversion branch July 6, 2026 01:15
jdatcmd added a commit that referenced this pull request Jul 6, 2026
CI, PHP 8.1-8.4 support, and array columns in rows (relanded #18 + #19)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants