Bug #78976 [Ver->Csd]: SplFileObject::fputcsv returns -1 on failure

From: Date: Tue, 17 Dec 2019 16:54:44 +0000
Subject: Bug #78976 [Ver->Csd]: SplFileObject::fputcsv returns -1 on failure
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224358@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78976&edit=1 ID: 78976 Updated by: cmb@php.net Reported by: nyamsprod at gmail dot com Summary: SplFileObject::fputcsv returns -1 on failure -Status: Verified +Status: Closed Type: Bug Package: SPL related PHP Version: 7.4.0 Assigned To: cmb Block user comment: N Private report: N New Comment: Automatic comment on behalf of cmbecker69@gmx.de Revision: http://git.php.net/?p=php-src.git;a=commit;h=4cd6d384bde0f0641e88ae5431d5b6bdfff4ac83 Log: Fix #78976: SplFileObject::fputcsv returns -1 on failure Previous Comments: ------------------------------------------------------------------------ [2019-12-17 16:41:56] cmb@php.net > Seems this BC is documented […] Indeed[1]. > but the fact that I get -1 instead of false when using > SplFileObject::fputcsv is the real bug. Yes. Thanks for reporting! [1] <https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.core.fread-fwrite> ------------------------------------------------------------------------ [2019-12-17 12:36:33] nyamsprod at gmail dot com Seems this BC is documented but the fact that I get -1 instead of false when using SplFileObject::fputcsv is the real bug. ------------------------------------------------------------------------ [2019-12-17 07:39:16] nyamsprod at gmail dot com Description: ------------ The behavior of fwrite/fputcsv and SplFileObject::fwrite and SplFileObject::fputcsv have changed in PHP7.4 when used with a non writable stream. see https://3v4l.org/ifpaa Reading the changelog I fail to see where this is mention so is it the now expected behaviour from PHP7.4+ or is it a bug ? Test script: --------------- <?php $spl = new SplFileObject('php://temp', 'r'); $fh = fopen('php://temp', 'r'); var_export([ 'SplFileObject::fputcsv result on failure' => $spl->fputcsv(['foo', 'bar']), 'SplFileObject::fwrite result on failure' => $spl->fwrite('foo'), 'fputcsv result on failure' => fputcsv($fh, ['foo', 'bar']), 'fwrite result on failure' => fwrite($fh, 'foo'), ]); Expected result: ---------------- array ( 'SplFileObject::fputcsv result on failure' => 0, 'SplFileObject::fwrite result on failure' => 0, 'fputcsv result on failure' => 0, 'fwrite result on failure' => 0, ) Actual result: -------------- array ( 'SplFileObject::fputcsv result on failure' => -1, 'SplFileObject::fwrite result on failure' => false, 'fputcsv result on failure' => false, 'fwrite result on failure' => false, ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78976&edit=1

« previous php.bugs (#224358) next »