this post was submitted on 15 Apr 2025
832 points (98.8% liked)

Technology

68991 readers
3733 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 2 days ago (1 children)

Intermingling PHP and HTML is one of PHP strengths

Eeeh, no. It's a bad practice in 2025. That was a good thing a decade ago.

Trying to modify this blocked CSS is going to be wayyyyyyyyyyyyyyyyyyyy easier than trying to modify a bunch of printed HTML strings broken up by multiple nested conditionals. Plus it’s just straight-up easier to read and straight-forward to understand what the function does right away.

True. But I was just looking at the source code of wordpress for 30 seconds. I could probably find worse.

To harp on this even more, one of the benefits of blocking HTML in this way is IDE highlighting.

Which isn't a problem if you use a template engine - as you should in modern applications.

I can’t think of a single system that doesn’t “stop PHP executing” at some point to output HTML in some way.

Not a single modern system does that. It's terrible practice and won't even pass automated code reviews with sane settings.

[–] [email protected] 1 points 1 day ago* (last edited 1 day ago)

Not a single modern system does that. It’s terrible practice and won’t even pass automated code reviews with sane settings.

What you're talking about is semantics. At a base level, whether you use a templating engine, include / require, or just straight up mix HTML / PHP - PHP "stops execution" to output to the browser. The few exceptions to this that I can think of is if it's instead handing off that responsibility to JS or some other frontend processor.

Templating engines are cool. They make it easier to separate your views from logic. It makes interloping more straight-forward and possibly more maintainable (though, not always - Engines don't save from bad practices), but I do not agree that it's defacto. I think the strength of PHP is it's ease to just jump into it and get something working, right "out of the box". The ease of mixing PHP and HTML is a boon from an entry level aspect. Low entry level leads to wider adoption, leads to more discussions, more volunteers for FOSS, more bug reports, more more more.

I could create a vanilla PHP application that organizes views just as well without a templating engine which could be understood by someone with baseline PHP knowledge - that's good thing. It's inherit to PHP and I won't need to worry about keeping any templating library updated or ported to a new engine. In my made-up vanilla app, I wouldn't do what 4chan did in their views, but I may do what WordPress does in your example because, used sparingly, in an organized application, it's not that big of a deal. For the most part though, I do like to keep my HTML views and my PHP logic separate in an MVC kind of way either through templating or just straight up includes.