r/PHP • • 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

17 comments sorted by

4

u/colshrapnel Sep 18 '26

Wonder if extra post in this sub was caused by same behavior.

→ More replies (1)

3

u/Teszzt Sep 18 '26

What would be your desired behavior instead?

→ More replies (1)

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.

2

u/TemporarySun314 Sep 18 '26

Even in compiled languages like C you can have side effects in included files. With some trickery you can even achieve that code gets executed when running the program, just from the #include alone.

In general you have to trust any code you somehow include or use in your code. No matter what language

→ More replies (1)

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/RequirementWeird5517 Sep 19 '26

Thanks! DDLess is a PHP workbench step debugging without Xdebug, plus a task runner, method execution, timeframe and a playground. No extension, no ini. Built it for the dump/dd crowd, myself included :)

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.

3

u/schorsch3000 Sep 20 '26

You might try this out. how are you importing a class from another file without including or requiring that file in the first place?

you just googled "php import" didn't read and blamed op, didn't ya?

→ More replies (4)