php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70034 ReflectionClass->getFileName in PHPT returns "-" as filename
Submitted: 2015-07-09 12:53 UTC Modified: 2015-07-10 17:25 UTC
From: james at asgrim dot com Assigned: cmb (profile)
Status: Closed Package: Reflection related
PHP Version: 5.6.10 OS: Ubuntu 15.04
Private report: No CVE-ID: None
 [2015-07-09 12:53 UTC] james at asgrim dot com
Description:
------------
The ReflectionClass_FileInfo_basic.phpt test is failing.

When creating a reflection of a class in a .phpt test, the getFileName() method returns simply a string with a hypen ("-") instead of the actual filename.

--- Expected
+++ Actual
@@ @@
-string(%d) "%sReflectionClass_FileInfo_basic.php"
+string(1) "-"

https://github.com/php/php-src/blob/master/ext/reflection/tests/ReflectionClass_FileInfo_basic.phpt

Expected result:
----------------
Expect the filename returned by getFileName() to be "%sReflectionClass_FileInfo_basic.php"

Actual result:
--------------
The filename returned by getFileName() is actually "-"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-09 14:42 UTC] cmb@php.net
-Status: Open +Status: Feedback
 [2015-07-09 14:42 UTC] cmb@php.net
The test passes for me, and apparently for others as well[1]. How
did you run the test (make test or directly via run-tests.php)?

[1] <https://qa.php.net/reports/run_tests.php?version=5.6.10>
 [2015-07-09 17:27 UTC] james at asgrim dot com
-Status: Feedback +Status: Closed
 [2015-07-09 17:27 UTC] james at asgrim dot com
Hmm - I'm running the test using PHP Unit, so this may be a bug there instead. I'll close this, investigate some more and re-open if it needs a closer look at here :)

Thank you!
 [2015-07-09 18:12 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2015-07-09 18:12 UTC] cmb@php.net
Ah, interesting! I didn't know that PHPUnit is able to run phpt
tests.

Anyway, I gave it a try on Windows, and got the following:

    --- Expected
    +++ Actual
    @@ @@
    -string(%d) "%sReflectionClass_FileInfo_basic.php"
    +string(43) "C:\Users\cmb\AppData\Local\Temp\PHP2C57.tmp"

So indeed, this seems to be a current limitation of PHPUnit.
 [2015-07-09 18:22 UTC] james at asgrim dot com
Yes indeed - further information if anyone comes across this:
https://github.com/sebastianbergmann/phpunit/issues/1783

It's actually because phpunit pipes the code into php on Linux (although, from your example there, it looks like it works by creating a tmp file and running that)

Incidentally, do you know of a way of "faking" the filename in this case?

e.g.

this fails:

echo "<?php class Foo {} \$c = new ReflectionClass('Foo'); var_dump(\$c->getFileName());" | php

is it possible to "fake" the filename, something like:

echo "<?php class Foo {} \$c = new ReflectionClass('Foo'); var_dump(\$c->getFileName());" | php --pretend-the-filename-is="foo.php"

or something?
 [2015-07-10 17:25 UTC] cmb@php.net
> Incidentally, do you know of a way of "faking" the filename in
> this case?

No, unfortunately not.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 01:01:28 2024 UTC