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
In times like this, it's actually fairly useful to be able to read a fair amount of Danish.
Merge branch 'v2022'
Go with 2022.16
Merge branch 'v2022'
Merge branch 'v2022'
Go with 2022.15
Do a shallow clone
Merge branch 'v2022'
Update data to 2025c
Merge branch 'v2022'
Update script for current PHP versions
I hold the domains phpvikinger.{org,net,com}, which are expiring in three months.
I am not going to renew them as I have no use for them any more.
If you're interested, let me know? It'll cost you just the normal registration fees.
I walked 4.8km in 44m52s
I walked 2.1km in 20m46s
I walked 5.8km in 1h12m05s
Robin
They usually never sit still long enough close by for a good photo. But this little bird was perched on this branch for several minutes letting lots of people take photos of it. When I started taking photos, it looked directly at me and my camera — it was clearly posing!
I walked 10.5km in 1h48m41s
I hiked 16.2km in 3h23m19s
Updated a restaurant
Updated a restaurant
I walked 8.7km in 1h25m51s
Merged pull request #1056
Add metadata header to CSV file
RE: https://phpc.social/@Tideways/115859809842500892


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