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
Created a chocolate shop and a restaurant; Updated 6 restaurants and an address; Confirmed 5 restaurants, a community_centre, and 3 other objects
Created a restaurant, a fast_food, and 2 other objects; Deleted a restaurant
I walked 8.5km in 1h31m45s
Created 2 buildings and a hairdresser shop; Updated a restaurant and an estate_agent office; Confirmed a cafe
I walked 2.2km in 38m09s
Merged pull request #1096
Bump actions/checkout from 6 to 7
Merged pull request #1095
Improve Tiverton Green mapping
Created 2 gates
I walked 7.1km in 1h23m15s
I walked 1.0km in 9m24s
Realign streets. They now have much less wide corners into each other.
Updated a fast_food
I walked 9.1km in 1h35m41s
I hiked 4.7km in 3h24m10s
I walked 6.7km in 1h12m03s
I walked 7.7km in 1h47m24s
Updated a pub
Updated a pub
Created a bar; Updated a bar; Confirmed a restaurant and a bar
I walked 8.1km in 4h3m56s
Updated a toilet
I walked 8.8km in 2h52m21s


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