3 ms·
If PHP would enforce MVC by not being part of an HTML file, it would have been a very nice language (minus the $ signs everywhere)...
by ronreiter 13y ago
If PHP would enforce MVC by not being part of an HTML file, it would have been a very nice language (minus the $ signs everywhere)...
- homersapien 13y agoWhy should PHP "force" anything? That's one of PHP's strengths: the ability to be everything from a simple dynamic webpage to a full blown app. That's like saying "I wish someone would make a hammer that only strikes nails, because I'm a poor craftsman and keep hitting my thumb." Love it or hate it, PHP will be around long after elitist devs turn their guns on noSQL and server side JS.
- neovive 13y agoI agree. At it's PHP is just a template language. There are many great PHP MVC framworks that have evolved over the years to incorporate many "best practices". The choice should be up to the developer depending on the project.
- jtreminio 13y agoI'm assuming you meant "At its core, PHP is just a template language." That's a ridiculous, extremely over-generalized assertion. I don't know of many "template languages" that treat classes as first-class citizens, has an in-depth, thorough unit testing framework, traits, closures, and and and. I'm sure you get my idea? PHP may have been much simpler at its inception - it is not the same beast now.
- Killswitch 13y agoITT: People who haven't used PHP since 4.2 think they know what the language is like and base all their opinions on a language version over 10 years old. I hate when PHP pops up here on HN, 90% of the people flapping their gabs don't or haven't used PHP for many many years, and when they did it was some Indian's crap code so they spend their time talking shit about a language because they had to fix a bug in Hinderbar's PHP spaghetti from 2003.
- anu_gupta 13y agoYeah, always those damn Indians and their crap code. Every other country's PHP developers write amazingly elegant PHP - it's just those damn Indians.
- jon_r 13y agoIf there's one thing I've learned in my years of software development it's that software is the great equaliser. Everyone is capable of writing crappy spaghetti code.
- leokun 13y agoYou didn't really have to add the racism to make that point.
- georgehotelling 13y agoWhile not enforced at the language level, PSR-1 states that "Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but SHOULD NOT do both." Basically it stipulates that you should keep classes outside of the main page loader to be compliant.
- easy_rider 13y agoThat's so funny. When I look at $'s in PHP, it feels so natural. Then when I see someone use $ in variable names in JS, it gets me agitated.
- ceejayoz 13y agoI typically reserve $ in JS variable names for a version of something that's jQuery-ified. i.e. $(this) = $this;
- captainmuon 13y agoActually the ability to mix PHP and "HTML" is the only reason I still use PHP occasionally. Sometimes, I have a plain-text file, and would like to use variables or simple loops in it. The best way to do this is PHP! For example, say I want to plot a couple of data columns with gnuplot (an open source plotting program) into several images. I can write a PHP script "myplot.plt.php" that generates a gnuplot script (untested): set terminal png enhanced <?php for ($i = 2; $i <= 4; $i++) { $outputfile = "plot$i.png" echo <<EOT set output "$outputfile" plot "data.txt" u 1:$i EOT; } ?> and then invoke it from gnuplot with load "< php myplot.plt.php" This is a stupid example, but it gets really powerful when you dynamically calculate labels, element positions, etc.. PHP may be a crappy language for web development, but it is a really nice macro language, and has really powerful string processing features, making it ideal for this kind of hack.