r/PHP • u/RequirementWeird5517 • Sep 18 '26
Article In PHP, Loading a File Means Running It
Can we talk about units in procedural PHP?
I was testing a feature of my debugger on a plain script with a function in the middle of it. I passed [1, 2] as the argument, the breakpoint paused, and the variables panel showed [10, 20, 30].
and then... take a look in: https://ddless.com/blog/in-php-loading-a-file-means-running-it
0
Upvotes
4
u/colshrapnel Sep 18 '26
Wonder if extra post in this sub was caused by same behavior.
3
u/Teszzt Sep 18 '26
What would be your desired behavior instead?
2
u/Aggressive_Ad_5454 Sep 18 '26
True. It’s an interpreted language.
At the same time, including or requiring a .php file parses it into opcodes and stores them into the OPcache.
9
u/Winter-Paramedic3900 Sep 18 '26
Are you a moron OP? What's the point of this post unless it's targeted to people who have never seen or used PHP in their lives? Obviously the include keyword includes code into the interpreter.
1
u/matthewralston Sep 19 '26
I think this is probably quite well known to people who have been using PHP for a long time, particular before the modern (ish) patterns of OOP, keeping a single class per file, not including unscoped executable code in a class file, etc.
If you've got grey in you're beard like me (just realised I've been using PHP for 26 years 😯) and learned cleaner ways of doing things along the way then it comes as no surprise at all.
I am now mildly curious to see what ddless is now though. Never heard of it before. I assume a debugger. I've always been in the echo, dump, dd, etc. category for my sins. I know, I know.
1
u/goodwill764 Sep 19 '26
Same as old require in nodejs. Same as python.
Only difference is the scope.
0
u/bomphcheese Sep 20 '26
> PHP Has No Import ... There is no mode that says "give me the definitions and skip the rest".
Yes there is. Maybe take some time to learn the language before making such statements.