**script.php**

```php
$filename = realpath(sprintf("%s/%s", getcwd(), $argv[1]));
var_dump($filename);

```

Let's try some things

```none
[/foo/bar/bof] $ php script.php ../foo.txt
string(16) "/foo/bar/foo.txt"

[/foo/bar/bof] $ php script.php ../nonexistent.txt
bool(false)

```

Dammit! `realpath` is returning false because the file doesn't exist.

What I'd like to see for the `../nonexistent.txt` is

```
string(24) "/foo/bar/nonexistent.txt"

```

**How can I get the canonicalized path for any relative path in PHP?**

**Note:** I saw some questions regarding resolving symlink paths. Answers to these questions are not applicable to my question.