Xuanwo opened a new pull request, #9296:
URL: https://github.com/apache/opendal/pull/9296
# Which issue does this PR close?
Refs #9278. Supersedes #9293.
# Rationale for this change
In PHP, `string` is a binary-safe sequence of arbitrary bytes tracked by
byte length rather than a UTF-8 text type. `OpenDAL\Operator::write($path,
$content)` previously bound `$content` as a Rust `String`, which enforced UTF-8
validation and rejected arbitrary binary strings. That bug predates the
`ext-php-rs` 0.15.15 to 0.16.5 upgrade in #9278, which only changed the error
raised for invalid UTF-8 content from `\Exception` to `\TypeError`.
Instead of documenting UTF-8 rejection as an upgrade note (the closed
documentation PR #9293), `Operator::write` should match PHP string semantics
and preserve every byte, consistent with `Operator::read` returning
`Binary<u8>`.
# What changes are included in this PR?
- `bindings/php/src/lib.rs`:
- Change `Operator::write` to take `content: Binary<u8>` (which declares
PHP `DataType::String` and reads the Zend string by byte length) and transfer
ownership of the raw bytes to OpenDAL via `Vec::from(content)`.
- Keep `path: &str` as UTF-8 text so invalid UTF-8 paths continue to be
rejected with `TypeError`.
- Keep `Operator::write_binary(path: &str, content: Vec<u8>)` unchanged
for backwards compatibility with callers passing byte arrays, and update doc
comments to recommend `write` for binary strings.
- `bindings/php/opendal-php.stubs.php`: Keep the existing parameter
declarations and update docblocks to describe byte-preserving `write` and
recommend `write` over `write_binary` for binary strings.
- `bindings/php/tests/Feature/BasicIOTest.php` and
`bindings/php/tests/Unit/BasicTest.php`:
- Add an arbitrary-bytes `write`/`read` round-trip test
(`"prefix\0\x80\xff suffix"`), assert strict multibyte UTF-8 round-trip
equality, and fix the `write_binary` tests to compare readback against the
original input.
- Update the invalid UTF-8 unit test to verify that an invalid UTF-8
`$path` still throws `TypeError` for argument `path`.
- `website/docs/20-bindings/php/01-overview.md` and
`website/docs/20-bindings/php/02-getting-started.md`: Document `write` as
binary-safe for PHP strings and note that `write_binary` remains available for
byte arrays.
Verification:
- **Baseline:** Unmodified `main` built against PHP 8.2.36 passed 25/26 Pest
tests and failed the new arbitrary-bytes string write test with `TypeError` for
`$content`; the same failure reproduced on the #9278 PHP 8.1.34 extension.
- **PHP 8.2.36 & 8.4.28:** Full 26-test Pest suite (`fs` and `memory`),
`cargo clippy -- -D warnings`, `getting-started.php`, and stub syntax check
passed.
- **PHP 8.1.34, 8.2.36 & 8.4.28 runtime probes:** Verified arbitrary binary
string round trip (`prefix\0\x80\xff suffix`), multibyte UTF-8, empty string,
`write_binary` byte-array round trip, invalid UTF-8 path `TypeError`, and
reflected method parameter/return types; PHP 8.1.34 also passed
`getting-started.php`, stub syntax check, and an independent full 256-byte
(`0x00`–`0xff`) round-trip test (Pest was run on PHP 8.2.36 and 8.4.28, not PHP
8.1.34).
# Are there any user-facing changes?
`OpenDAL\Operator::write(string $path, string $content)` now accepts
arbitrary binary PHP strings and preserves every byte instead of rejecting
non-UTF-8 content. `Operator::write_binary(string $path, array $content)`
remains supported for byte arrays, and `write` is now recommended for binary
strings. PHP binding stubs and website docs are updated accordingly. No
`upgrade.md` entry is needed because existing PHP signatures remain compatible
and no migration is required.
# Breaking changes
# AI Usage Statement
- **Harness:** Pi (via T3 Code)
**Model:** `magpie/codex/gpt-6.2-sol`
**Effort:** `max`
**Role:** Implemented the `Binary<u8>` change, updated PHP stubs, tests,
and docs, and ran baseline and candidate verification across PHP 8.1.34,
8.2.36, and 8.4.28.
- **Harness:** Pi (via T3 Code)
**Model:** `magpie/codex/gpt-6.2-sol`
**Effort:** `high`
**Role:** Independently reviewed the candidate commit and ran an
independent PHP 8.1.34 full 256-byte (`0x00`–`0xff`) round-trip check.
- **Harness:** Pi (via T3 Code)
**Model:** `magpie/codex/gpt-6.2-astra`
**Effort:** `high`
**Role:** Coordinated triage from #9278 and closed PR #9293 to the
byte-preserving fix, independent review, and publication gating.
- **Harness:** Pi (via T3 Code)
**Model:** Gemini 4 Neon
**Effort:** `high`
**Role:** Drafted this PR description from the signed candidate commit and
local verification records, rechecked publication preflight (commit signature,
clean integration onto `main`, duplicates, and CI queue), and published this
PR. Assumptions/unknowns affecting review: PHP 8.1.34 was verified with
standalone runtime probes and the independent 256-byte test rather than the
Composer/Pest suite, which ran on PHP 8.2.36 and 8.4.28.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]