3 ms·
This isn't really true anymore. Namespaces, as ugly as they are visually, plus autoloading plus a package manager that handles it for you allows quick structuri
by jwdunne 11y ago
This isn't really true anymore. Namespaces, as ugly as they are visually, plus autoloading plus a package manager that handles it for you allows quick structuring of a project. This can be configured to fit whatever conventions you prefer but the community has put out there a set of good conventions in the form of PSR docs so you can get started quickly.
The whole mixing of HTML with PHP with SQL is bad form and is widely discouraged. In fact, this code is often seen with usage of mysql_ functions plus manual escaping and interpolation. This is discouraged to the point where that library has been removed.
I'm no evangelist, I prefer other languages, but with these "good parts" so to speak, the language is usable and supportive of good structure. We have had these improvements relatively late in the game but they do appear to come thick and fast nowadays.
There are many warts in the language. Sometimes I'm angered when very good ideas for progress are shot down via committee. There has, however, been improvement since PHP 4.
- maruhan2 11y agoCould u explain why HTML&PHP&SQL is bad? And is it only bad when all three are combined?
- tehbeard 11y agoseparation of concerns and DRY would be the two main reasons I'd put forward. Anything involving manipulating your data / business logic should not be embedded in a template. PHP in your html should really be for display/rendering (i.e. looping over a list of Employee records), it should not be fetching those records itself (either by Employee::fetchAll() or especially mysql_query("SELECT * from employee") )
- jwdunne 11y agoI don't think you should have been down voted for this question. It discourages asking to learn. What I meant was mixing them together in the same piece of code. The other comments explain why: its doing too much, its difficult to maintain and reason about so its harder to find bugs, especially serious ones, and difficult to fix them.
- foxhop 11y agoResearch "model view controller" and separation of concerns. It is very hard to maintain or even reason about a file or make a change or secure exploitable edge cases when the application has html, css, javascript, php, and calls to the database in the same place.