php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #24162 some filesystem functions return bool, not int (as advertised)
Submitted: 2003-06-12 17:32 UTC Modified: 2003-06-22 20:10 UTC
From: marcus at gooseflesh dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.2 OS: Windows 2000
Private report: No CVE-ID: None
 [2003-06-12 17:32 UTC] marcus at gooseflesh dot de
Description:
------------
Hello folks,

Of some reasons the return value of ftruncate($handle, $size) is of type int not of type bool. 

Is there a general reason that the half of the file functions return true and false as int and the other half true and false as bool ???

Marcus Wilhelm

PHP is the best :))

Reproduce code:
---------------
$handle = fopen("existing.file", "r+");

$return = ftruncate($handle, 17);

if ( $return === true ) // does not match
{
    echo "truncate ok, return value is bool"; 
}
if ( $return == true ) // does match
{
    echo "truncate ok, return value is bool or int"; 
}
if ( $return == 1 ) // does match
{
    echo "truncate ok, return value is int"; 
}

Expected result:
----------------
the return value of ftruncate should be of type bool not of type int.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-12 20:05 UTC] philip@php.net
It returns bool and is documented as such, thanks for the report.
 [2003-06-12 20:42 UTC] philip@php.net
I went through every reference/filesystem function and appropriately changed the following from int to bool:

chgrp.xml chmod.xml chown.xml copy.xml link.xml mkdir.xml rewind.xml rmdir.xml symlink.xml touch.xml unlink.xml

They will show up during the next manual build, thanks for the report! :)
 [2003-06-13 00:17 UTC] torben@php.net
Just to clarify: this changed after the release of 4.3.2, so currently, the documentation is not in fact accurate for the released version. However, the return type will be boolean for the next release, unless someone decides to change the behaviour back.

For what it's work: before version 4.3.2, ftruncate() returns boolean FALSE if something in the PHP ftruncate() fails. Otherwise, an integer is returned which indicates the return value of the ftruncate() system call...on Linux, this
would be 1 for success and 0 for failure. So Marcus, you were in fact correct with your original bug report.


Thank you for the report, and I hope this clarifies matters.

Torben
 [2003-06-22 20:10 UTC] philip@php.net
This changed behavior with ftruncate() has been documented.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 26 15:01:37 2024 UTC