php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79389 ftell retruns false on linux for STDIN
Submitted: 2020-03-17 14:00 UTC Modified: 2020-03-18 08:06 UTC
From: mail at ahmd dot io Assigned:
Status: Verified Package: Streams related
PHP Version: 7.4.3 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mail at ahmd dot io
New email:
PHP Version: OS:

 

 [2020-03-17 14:00 UTC] mail at ahmd dot io
Description:
------------
Hi

ftell php function returns false for STDIN on Linux with all php 7.4 versions 
https://3v4l.org/LTbpu

The related commit seems to be this one 
https://github.com/php/php-src/commit/c1a6f2b9ccd2f022b8b0a056030a287748e98eaa#diff-093fc4d3c1dfbb6819809690e36128d7L246

Test script:
---------------
<?php
var_dump(ftell(STDIN));


Expected result:
----------------
int(0)

Actual result:
--------------
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-17 18:28 UTC] cmb@php.net
-Assigned To: +Assigned To: nikic
 [2020-03-17 18:28 UTC] cmb@php.net
Well, the behavior depends on which kind of file stdin refers to.
If it is a pipe, the PHP 7.4 behavior makes more sense to me.
Anyhow, the mentioned commit is not the cause of that behavioral
change (it is not even contained in PHP 7.4.0).

@nikic, is this indeed intended behavior?
 [2020-03-17 18:54 UTC] nikic@php.net
@cmb: Yes, character devices are not seekable, so ftell should return false.
 [2020-03-18 08:06 UTC] cmb@php.net
-Status: Assigned +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: nikic +Assigned To:
 [2020-03-18 08:06 UTC] cmb@php.net
ftell() for character devices already returned false in earlier
PHP versions; the behavioral change reported by the OP appears to
be related to pipes.  Anyhow, not seekable => ftell() returns
false, makes perfect sense to me.
 [2020-03-20 16:00 UTC] mail at ahmd dot io
Got it now, thanks for clarifying 

I tried to amend ftell docs in the manual using edit.php.net
but it's my first time to touch php docs, hopefully, I did it correctly and did not miss anything :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC