Category
stdlib
Problem
fputcsv() is implemented for basic cases but does not match Zend for empty enclosure (ValueError) and empty escape character (PHP 8.4+ rules), multi-byte separators, or TypeError vs LogicException on bad handle types.
VM path: ext/standard/fputcsv.php + VmFs; defaults separator=',', enclosure='"', escape='\\' with no validation.
php-src reference
- php/php-src
ext/standard/file.c — PHP_FUNCTION(fputcsv) (_php_fputcsv)
- PHP 8.4: empty
$escape allowed only when $enclosure is non-empty one-byte string; otherwise ValueError
Repro
Save as test/repro-maintainer/fputcsv_escape.php:
<?php
$fp = fopen('php://memory', 'r+');
foreach ([
['escape' => ''],
['enclosure' => ''],
] as $case) {
try {
fputcsv($fp, ['a'], ',', $case['enclosure'] ?? '"', $case['escape'] ?? '\\');
echo "no throw\n";
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
}
php test/repro-maintainer/fputcsv_escape.php
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro-maintainer/fputcsv_escape.php'
Expected on PHP 8.4+ (Zend, document exact message from php -v in Docker)
| Case |
Zend |
escape='' (PHP 8.4+) |
ValueError — escape must be empty only with valid enclosure per RFC |
enclosure='' |
ValueError — enclosure must be exactly one character |
Record actual message strings in the compliance PHPT header when implementing.
Actual (this compiler)
Often no throw or LogicException on bad handle type instead of TypeError.
Scope
ext/standard/fputcsv.php, ext/standard/VmFs.php
lib/JIT/Builtin/ fputcsv lowering if present
test/compliance/cases/stdlib/fputcsv_escape.phpt, fputcsv_bad_handle.phpt
Done when
Links
Category
stdlib
Problem
fputcsv()is implemented for basic cases but does not match Zend for empty enclosure (ValueError) and empty escape character (PHP 8.4+ rules), multi-byte separators, orTypeErrorvsLogicExceptionon bad handle types.VM path:
ext/standard/fputcsv.php+VmFs; defaultsseparator=',',enclosure='"',escape='\\'with no validation.php-src reference
ext/standard/file.c—PHP_FUNCTION(fputcsv)(_php_fputcsv)$escapeallowed only when$enclosureis non-empty one-byte string; otherwiseValueErrorRepro
Save as
test/repro-maintainer/fputcsv_escape.php:php test/repro-maintainer/fputcsv_escape.php ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro-maintainer/fputcsv_escape.php'Expected on PHP 8.4+ (Zend, document exact message from
php -vin Docker)escape=''(PHP 8.4+)ValueError— escape must be empty only with valid enclosure per RFCenclosure=''ValueError— enclosure must be exactly one characterRecord actual message strings in the compliance PHPT header when implementing.
Actual (this compiler)
Often no throw or
LogicExceptionon bad handle type instead ofTypeError.Scope
ext/standard/fputcsv.php,ext/standard/VmFs.phplib/JIT/Builtin/fputcsv lowering if presenttest/compliance/cases/stdlib/fputcsv_escape.phpt,fputcsv_bad_handle.phptDone when
./script/ci-fast.sh --filter fputcsvgreenLinks