Contributing Advent 8: The magic __FILE__ constant
This issue came up in the #xdebug IRC channel on Freenode:
18:25 <user> no magic constants for PHP ? 18:27 <user> __FILE__ evaluates to "xdebug://debug-eval"
The user noticed this issue in the Eclipse expression evaluator. A similar issue is also described a few times on the internet:
With the hint in comment 2 in the first URL, I answered the report in an answer on StackOverflow (the third URL). I am repeating this answer (with some modifications) here:
The output you get is not incorrect. __FILE__ is a special constant that gets evaluated at parser time. In fact, even though it looks like a constant, it is really not. When the PHP script gets compiled, it would really read something like this:
// test.php
<?php
"test.php";
?>
even though the script source was:
// test.php
<?php
__FILE__;
?>
This means that after parsing, there is no such "constant" __FILE__ at all, as it has already been replaced.
This means that if you evaluate __FILE__ in an IDE, through DBGp's eval command with eval -- __FILE__ it can not return you a filename that is represented through the __FILE__ "constant". Instead, it uses the filename for the current context which is xdebug eval or in later versions, xdebug://debug-eval.
In essence, it's the same as doing this:
php -r 'eval("__FILE__;");'
Which also outputs:
Command line code(1) : eval()'d code
Xdebug looks for this sort of output format, and changes it to xdebug://debug-eval so that it can actually debug into eval'ed code.
__FILE__ works as expected in "normal" PHP source code, as can be proven with this snippet:
<?php $currentFilename = __FILE__; ?>
And after it has been assigned to a variable, you can evaluate $currentFilename in your IDE.
Life Line
π· Tufted Duck Pair
π© Outer Circle, City of Westminster, United Kingdom
RE: https://phpc.social/@Xdebug/115662135830755552
I have just released Xdebug 3.5.0!
In the next few weeks I will create some content (text, and perhaps video) highlighting some new features in more detail.
Please share it with the world!
The master branch is now for Xdebug 3.6, targetting PHP 8.6
Back to -dev
Tweak release instructions a little
Go with 3.5.0
Tweak message IDs and severities for control socket log entries
I walked 8.5km in 1h30m56s
My whisky of the month for December 2025, is a 15yo Aultmore bottled by Cadenhead's.
Fixed off-by-one error in address length name for control socket on Lβ¦
Merged pull request #1050
Fixed control socket name by removing silly trailing things (by not pβ¦
RE: https://en.osm.town/@harry_wood/115650834037247679
Fancy a friendly #OpenStreetMap chat in the pub, with some Christmas celebrations?
The London OSM gang is meeting on December 16th near Paddington.
I walked 8.7km in 1h29m30s
RE: https://mastodon.online/@afup/115648919275171255
This talk on what's New in PHP 8.5 is in English! Je ne parles pas FranΓ§ais!
I walked 10.0km in 1h46m14s
Merged pull request #1049
Reorder xdfree(name) and removing trailing whitespace
Tweak comments to use /* .. */ style
Reuse created \\.\pipe name


Shortlink
This article has a short URL available: https://drck.me/adv1308-aex