Bug #69163 [Opn->Fbk]: fopen(__DIR__, 'r') succeeds

From: Date: Wed, 04 Mar 2015 01:05:01 +0000
Subject: Bug #69163 [Opn->Fbk]: fopen(__DIR__, 'r') succeeds
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191113@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69163&edit=1

 ID:                 69163
 Updated by:         danack@php.net
 Reported by:        salsi at icosaedro dot it
 Summary:            fopen(__DIR__, 'r') succeeds
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            Streams related
 Operating System:   Linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

"A Linux system, just like UNIX, makes no difference between a file and a directory, since a
directory is just a file containing names of other files."

From the manual:

Note: This function may also succeed when filename is a directory. If you are unsure whether
filename is a file or a directory, you may need to use the is_dir() function before calling fopen().

Are you sure this actually should be treated as a bug?


Previous Comments:
------------------------------------------------------------------------
[2015-03-02 20:22:46] salsi at icosaedro dot it

ERRATA/CORRIGE. In my test script, the line

    $f = fopen(__FILE__, 'r');

should contain a directory, for example:

    $f = fopen(__DIR__, 'r');
    $f = fopen('.', 'r');
    $f = fopen('..', 'r');

Thanks to Richard Gray for signaling this bug in my report.

ADDENDUM. Under Windows Vista fopen() fails on a directory, as it should.

------------------------------------------------------------------------
[2015-03-02 19:16:32] salsi at icosaedro dot it

Description:
------------
On Linux, opening a directory succeeds; subsequent reads always returns string("") and
feof() is true, no warnings.


Test script:
---------------
<?php
error_reporting(PHP_INT_MAX);
$f = fopen(__FILE__, 'r');
var_dump($f);
for($i=0; $i<3; $i++){
	echo "feof is "; var_dump(feof($f));
	echo "fread returns "; var_dump(fread($f, 10));
}


Actual output:
----------------------------------
resource(5) of type (stream)                                                                        

feof is bool(false)                                                                                 

fread returns string(10) "<?php                                                             
        
erro"                                                                                          
     
feof is bool(false)                                                                                 

fread returns string(10) "r_reportin"                                                     
          
feof is bool(false)                                                                                 

fread returns string(10) "g(PHP_INT_"  

Expected result:
----------------
Expected output:
-----------------------------------
E_WARNING: cannot open directory
boolean(false)
...



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69163&edit=1


Thread (5 messages)

« previous php.bugs (#191113) next »