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 2 waste_baskets, 2 boards, and 2 benches; Updated 8 benches, 6 waste_baskets, and 2 other objects; Deleted 2 waste_baskets and a bench
Updated a pub
Merge branch 'v2022'
Merge branch 'php_gh_19803' into v2022
Fix PHP GH-19803: Parsing a string with a single white space does cre…
Merge branch 'xdebug_3_5'
Back to -dev
Go with 3.5.1
Thanks Brussels, you've been lovely to me this weekend.
And I've a lot to process from the conference too.
I walked 3.9km in 36m24s
I walked 1.1km in 11m31s
Updated a restaurant; Confirmed 3 fast_foods, a convenience shop, and 2 other objects
I walked 4.4km in 44m06s
I walked 5.1km in 56m16s
I walked 3.8km in 37m43s
I'm up early to get the Eurostar to #FOSDEM and I've already seen friends being made.
Fixed another address
Fixed address for flats
Fixed address, and ass missing service way
I walked 6.4km in 1h20m58s
I walked 11.4km in 9m22s
I walked 10.4km in 1h41m18s
I walked 7.4km in 1h26m49s
Good job antivaxer shit heads:
BBC News: UK loses measles elimination status
I walked 8.2km in 1h24m04s


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