5 ms·
Wrong. Other languages require templating systems that won't allow you to dump variables because they won't be in scope in the first place. Using PHP in HTML a
by codesushi42 7y ago
Wrong. Other languages require templating systems that won't allow you to dump variables because they won't be in scope in the first place.
Using PHP in HTML allows you to do just that.
- debaserab2 7y agoUh, no - templates are scoped to the function or method in which they are called. They are only global if you include the template globally. class MyTemplate { function displayTemplate() { include 'mytemplate.php'; // mytemplate.php has access to only class properties. // Anything declared within mytemplate.php is scoped to the displayTemplate function. } }
- codesushi42 7y agoUh, that is a contrived example not suggested by the op. You can still embed PHP into HTML.
- debaserab2 7y agoUsing class methods to scope template variables is contrived? Huh?
- codesushi42 7y agoYou can still embed PHP into HTML.
- csande17 7y ago> Other languages require templating systems that won't allow you to dump variables because they won't be in scope in the first place. This isn't true of every templating system in popular use. Rails's Action View, if I recall, allows you to stick <%= ENV["THE_DATABASE_PASSWORD"] %> into a template with no fuss at all, and yet Rails developers somehow manage to avoid doing that. PHP isn't bad because it lets you put code in HTML, it's bad because the default behaviors and APIs it provides make it easy to shoot yourself in the foot. A better, safer language could keep PHP's ease of deployment without its issues. Maybe P++ will be that language and maybe it won't.
- codesushi42 7y agoThat's not the same. I have seen plenty of unmaintainable PHP code that embeds business logic in HTML.