php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #69339 realpath(false) returns CWD
Submitted: 2015-03-31 09:04 UTC Modified: 2015-03-31 10:53 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sebastian@php.net Assigned:
Status: Open Package: Filesystem function related
PHP Version: 5.6.7 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-03-31 09:04 UTC] sebastian@php.net
Description:
------------
realpath(false) returns the CWD. This is the behavior that the manual describes for blank or NULL values: "Whilst a path must be supplied, the value can be blank or NULL In these cases, the value is interpreted as the current directory."

Either this is a bug in PHP or the documented needs to be amended.



Test script:
---------------
<?php
var_dump(realpath(false));
var_dump(realpath(true));
var_dump(realpath(0));
var_dump(realpath(null));
var_dump(realpath(''));


Expected result:
----------------
bool(false)
bool(false)
bool(false)
string(8) "/home/sb"
string(8) "/home/sb"


Actual result:
--------------
string(8) "/home/sb"
bool(false)
bool(false)
string(8) "/home/sb"
string(8) "/home/sb"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-31 10:52 UTC] cmb@php.net
Having a look at the implementation of realpath[1], there is
nothing special with the arguments '' or NULL happening. Actually,
realpath expects a string, so other argument types will be juggled
to string, and an empty string is treated as relative path.

That's seems to be pretty fine, so I'm changing to "Documentation
Problem". However, I'm not sure that it makes sense to document
special cases such as NULL and FALSE(or even
simplexml_load_string('<foo></foo>')).

[1] <http://lxr.php.net/xref/PHP_5_6/ext/standard/file.c#2306>
 [2015-03-31 10:53 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Jul 16 10:01:53 2018 UTC