6 ms·
Fear not, PHP when used appropriately can be fantastically useful. Pretty much every argument against it that I've read has centered around trying to do somethi
by PebblesHD 11y ago
Fear not, PHP when used appropriately can be fantastically useful. Pretty much every argument against it that I've read has centered around trying to do something it wasn't meant to do and not being very good at it. As a web scripting language, it works as advertised :-)
- pyre 11y agoI've heard that it's not very good at the "web app" paradigm vs. the "cgi script" paradigm that it was created in. Is that really true?
- girvo 11y agoNot in 2015 it's not! Front-controller pattern (single index.php, in the same way you'd have a single Python process that Nginx talks to) that hands off to something like Silex or Symfony or Laravel, and you have a beautiful base for a proper web application API layer -- autoloaded classes, proper dependency injection, and more.
- fsk 11y agoI never liked the pattern of routing every single request through index.php. I prefer to let Apache do the routing for me, having a separate script for each task. I also had a PITA debugging someone else's code with autoload magic. He didn't follow any pattern for what code was in which directory, and he reused class names so grep didn't work. Now where is that source file again? (In one particular abomination, he took a string from the database and included that source file.) That's one nice thing about PHP. You can use PHP for a simple straightforward style, or for an abomination like zend. Vanilla wordpress is good. I'm working on a project that has a custom framework that lives on top of WordPress, and I'm cursing the people who wrote it and my employer for outsourcing the WordPress project to them.
- vectorpush 11y ago> He didn't follow any pattern for what code was in which directory, and he reused class names so grep didn't work. Now where is that source file again? http://www.php-fig.org/psr/psr-4/ http://www.php-fig.org/psr/psr-4/
- fsk 11y agoNope, he didn't follow that, he had a bunch of exceptions coded in his autoload function. He also had a bunch of functions where a function in one class nothing but call another function in another class. He also had way too many classes.
- girvo 11y agoRight, but that's the problem. You can quite easily make an abomination of a class hierarchy in Ruby, or Javascript, or even Python to some extent. If people don't follow best practices, then of course things will not work with other tools that expect your work to do so. Also, I highly recommend XDebug with the Codebug[0] client -- if you're working with a crappy codebase and run into the issue of "what damned file is this?" it will solve that in a super nice way. It also gives you a full REPL in your working environment, pause execution and play around in the PHP side during your request :) [0] http://codebugapp.com http://codebugapp.com
- fsk 11y agoI'll look into Codebug. I haven't found a PHP editor I really like yet. I've been using dev-PHP and emacs. I'm using Netbeans at work and don't like it. Oh nevermind, Mac only, forget it.
- PebblesHD 11y agowell said. Personally I like the file based routing solution (Multiple scripts for individual tasks) where applicable, there are benefits to multi-function scripts but I like modularity. If i've already written a script to do X, why re-write it every time? Still All these points above and below are good.
- girvo 11y agoThe key benefit to the front-controller architecture is that you can keep your code outside of the webroot, such that you can avoid misconfigurations causing security issues, and allowing for user uploads without exec permissions on the files in the uploads directory. The other reason I like it is it gives me much more control over routing, versus relying on folder and file structures :)
- vectorpush 11y agoI'm not really sure there is much of a difference between the two beyond routing (which the framework handles just like in all the other popular imperative scripting languages), in fact if anything I'd say PHP is more aligned with the "web app" paradigm since the canonical run-times are all intended to be paired up with an HTTP server, as opposed to most others which were designed as general purpose scripting languages. I don't think it makes much of a difference though.
- imakesnowflakes 11y ago>PHP when used appropriately 'using php appropriately' involves keeping a large number of gotchas and weird behaviors in your head, when you are writing every single line of PHP.