I teach web development at a university. We have used, java, javascript, python and php for a basics course in webdev.
Php has built in web features and one doesnt need more than a php interpreter (considering the built in web server as well) to get started. For all other languages i know of, there is quite a process to get started (e.g. start with python flask one needs a package manager, environment variables, command line experience, ...). Php is a web native language and great for learning and getting started.
> needs a package manager, environment variables, command line experience
Is this not the same with PHP? If you want to use packages then you'll need to use a Package manager, you still need command line experience etc.
Node.js comes with a package manager NPM, and has no need for anything like virtualenv's to keep packages separate per project.
Python doesn't need virtual env's at all, it's just good practice.
And to be fair, as a naive non-PHP user, I have 0 clue how you would go about setting up long running scripts that don't necessarily correlate to a web request.
The thing about PHP is that the language has built-ins for almost everything you need for classic web development.
Want to use a relational database? You don't need to install a library (often one that requires a C extension in a language like Python or Ruby). It's just part of the language. Just do `$mysqli = new mysqli("localhost", "my_user", "my_password", "world"); $result = $mysqli->query("SELECT * FROM x");`.
Want to get things out of the HTTP request? PHP has already parsed everything into the `$_REQUEST` associative-array (map/dictionary). You don't need something like Flask or Node to deal with decoding the request.
Cookies, response writing, uploaded files, GET/POST vars, sessions, and many more things for web development are built-in. Heck, PHP even simplifies templating because PHP is literally its own templating language.
If someone gave you Python without any packages, would you be able to handle a request, see a GET variable, and put it into a page? I haven't used PHP in a decade and I can immediately think how to do that. OK, create index.php with whatever HTML I want in there and then put `<?= $_GET['theVarName'] ?>`. Done. That's it. If I want to get something from a db based on that get var, it literally has the functions/objects to connect to and retrieve stuff from the db. With Python, are you going to write your own database driver? With Python, are you going to open a socket and start manually handling all the HTTP stuff?
I'm not arguing that PHP is a better language than Python. I'm just saying that it was literally built to handle web requests and create the kind of web app that a lot of people make. The point is that with PHP, you usually don't need to do anything. You can just create a file with the `.php` extension and put in bits of dynamic code and the language has everything you need to create an app of the kind users expect without having to add libraries.
Does this matter? I don't think it does most of the time. I think OP's point was that PHP gets new people from nothing to "WOW, it's showing up on the screen!" with almost no effort. "OMG, I can save the form to the database and then display the information!" Tools have gotten a lot better for a lot of languages over the past decade. Still, nothing beats the ease of not having to deal with anything. PHP offers that.
PHP also offers a dead-simple deployment. You put your files on a server with PHP installed and you're done. Lots of shared hosting supports this precisely because the PHP language includes most of what people want to use. Because the language includes these things, that code is shared between all the users on the server rather than re-parsed and re-stored in memory and re-executed for every user. I mean, if a bunch of people are using Python, they're all going to bring DB libraries with them and many will be slightly different versions, etc. Likewise, some will use Django, some Flask, some other libraries - and again, all different versions. That makes hosting a bit more expensive (though that has gotten cheaper with serverless).
Most of the time if you want a library, you can download a directory of files and then use `require` or `include` to bring it in using relative paths. No worrying about environments or installing things. Just copy a folder!
That's the thing about PHP: it's basically a language and web framework in one with a simple development model.
I don't think PHP is a great language. However, I think it's important to understand why it was so successful. Back in the day before Xen and VPSs, it was hard (expensive) to get a server with root or get someone to install a package on a server for you. Virtualenv wasn't around forever (I remember easy_install before pip). You'd come across things that you just couldn't use. You'd end up fighting with a lot of things. You'd have to start long-running processes or use fcgi or all sorts of things that were annoying. Today, it's a much better landscape - partly because tooling has gotten better and partly because compute and RAM costs have gone down. But back in the day, you could just stick an `index.php` file in a directory set up for you and go to town. Instant gratification with zero setup. Even today, we use tools like NPM, Yarn, Virtualenv, pip, RVM, Gems, etc. to manage things. And I think that libraries are a lot better than having all those things built into the language. However, if you're looking for someone to be instantly productive on a live server, PHP does that. You never have to reload things or stop processes or set up a reverse-proxy. You never have to install anything (presuming the server has PHP set up).
Again, I think that libraries are better. They let you upgrade code without a language update. I think package managers are better than just downloading directories and copying them into a folder. I think that a long-running processes has a lot of benefits over re-evaluating the code every time (and PHP has modes that support this, I believe). But the interesting thing about PHP is that you don't need to do any of those things which do incur cognitive overhead. I mean, I don't want to be a PHP programmer, but if you're looking to take a student with one CS course under their belt and give them some instant joy, PHP really hits the mark.
Even the way you can program simple things is so easy. Ok, we all get directory trees and so if I go to `/apple/pear.php` the web server will execute that file. I don't think that routing in Flask is that hard, but there's more indirection. We can just go to pear.php and make it whatever we want. Again, this isn't about clean design and many advanced PHP projects use their own routing. This is about someone who doesn't know much being able to access GET/POST variables, call functions with SQL statements in them, and generate some HTML. No MVC, no DRY, no whatever. Just code that executes top to bottom in that file. Maybe you've used `require` or `include`, but again, that's just like copy/pasting that file at that point in the code - and it can be done anywhere and do anything including output HTML.
To be fair to PHP, I don't think good PHP is written that way. I just think there's a somewhat special simplicity to being able to just start writing random code in a file and have a web server execute it - and that code can do real stuff. No libraries, no configuration, no worrying about how the whole application is laid out. Just a file that executes. And before VPSs and such, it was so much easier. If you don't remember years like 2008, there are amazing threads about people trying to deploy things like Rails apps and the problems they encountered. It wasn't like today where we have much better tooling - but PHP always just let you upload some files that it would execute.
Sorry for this rambling thing. I don't think you should be learning PHP or anything, but I'll always have a bit of a special place for it because it made programming real things really accessible when I was an undergrad. I wasn't going to be renting a server with 1GB of RAM for $100/mo to run a Java project. Even a smaller server to run some Ruby or Python would have been more expensive and required a lot more work (which, frankly, I wasted a lot of time doing out of interest, but that's beside the point). PHP let me get something for $5/mo and just stick files on a server that someone else admin'd that would just work. I didn't have to do security patches, monitoring, process management, etc. I could just write some files that spit out some HTML, read GET/POST vars, handled sessions and cookies, connected to databases, etc.
> Want to use a relational database? You don't need to install a library (often one that requires a C extension in a language like Python or Ruby). It's just part of the language.
I'm being pedantic here, but technically it's still a C extension that most package managers install by default.
Yea, I was thinking about writing that, but it seemed really pedantic given that it's basically always there. I mean, Python never comes with Flask or a MySQL driver. You never end up paying for a PHP host without it. But you are technically correct, the best kind of correct!
> Most of the time if you want a library, you can download a directory of files and then use `require` or `include` to bring it in using relative paths. No worrying about environments or installing things. Just copy a folder!
There are gazillions of libraries at packagist.org, meaning these are installable via composer. Many of these expect composer to resolve dependencies. Major frameworks can't practically be installed without composer.
> PHP let me get something for $5/mo and just stick files on a server that someone else admin'd that would just work.
There are cheap cloud solutions for most languages...
> PHP also offers a dead-simple deployment. You put your files on a server with PHP installed and you're done.
... with push-to-deploy.
> Heck, PHP even simplifies templating because PHP is literally its own templating language.
And yet we had alternate templating engines for PHP since forever (remember Smarty ? know Twig now ?). Stuffing templates with "htmlspecialchars" or "htmlentities" is no fun.
> if you're looking to take a student with one CS course under their belt and give them some instant joy, PHP really hits the mark.
As stated, Javascript is better at this.
I could go on, but my point is that you're describing qualities that were competitive advantages in the past (somewhere between 1 and 2 decades ago), but are no more.
> And yet we had alternate templating engines for PHP since forever (remember Smarty ? know Twig now ?). Stuffing templates with "htmlspecialchars" or "htmlentities" is no fun.
One of the best decisions after I decided to stick with PHP for my web site was ditching all those alternatives and go with PHP alone, using functions as tag libraries.
It seems too low tech to be useful for any project of any complexity. Existing HTML template frameworks do a lot of things like character and syntax aware data escaping (and avoiding double-escaping), template caching, plugins, code generation, tag extension, filters, etc.
Other than being slightly more concise and appearing more functional, I don't see the benefit of this over something like Twig or Smarty. At some point you're going to wind up re implementing features that already exist in a framework anyway.
Low-tech is fine, however I'll assume your example has been excessively simplified for the sake of brievity because as-is it's prone to break your page.
Maybe PHP is a shitty language if you're coming from a CS background but Javascript is absolutely not better at "looking to take a student with one CS course under their belt and give them some instant joy". It's FAR more complex than PHP
I won't argue about the complexity and I'm not a fan of JS either... but surely you can agree that firing a browser console and do live dom manipulations can bring instant joy ?
I am baffled by the argument that's repeatedly advanced in different comment threads in this post: that php is easy for complete novices in web development to pick up, and that therefore... something. It reinforces the mindset that php is an entry-level language for amateurs; and if this is the case, then why would you want to keep using it for professional development once you are past your first web dev baby steps?
So with php is definitely possible to build large web apps as it is possible with other stacks. However compared to other languages with php it is very easy to get started as well as mainly the first dev setup is quite easy, although for professional work there might be no difference between the different stacks...
On my systems, I like to alias it so that I just have to type:
composer install
Alternatively, if you use a Jetbrains IDE (i.e. PHPStorm), you can usually install dependencies with one click.
> And to be fair, as a naive non-PHP user, I have 0 clue how you would go about setting up long running scripts that don't necessarily correlate to a web request.
php /path/to/script.php
It can run as long as you'd like.
If you want to do it on demand (i.e. writing a webserver in PHP), that's difficult. But generally: Why would you want to do that? It becomes an X-Y Problem.
I don't think the person you're replying to said it was not possible with PHP. Just that similarly to other languages where it's just as straightforward as the example you gave, it's not built-in.
What you probably meant is "run it from cron, or create an OS service that starts from init.d/systemd/whatever". Which answers the question, but isn't very impressive from a technology stack.
I kinda meant both. I feel silly not knowing that it's only "php ./script.php".
I also meant long-running processes, which it sounds like is still problematic. To be fair, it doesn't sound like PHP was ever designed to be used for long-running processes, to which I guess "Fair enough", but that might make things like a job worker queue more complicated if you want to write the workers in PHP (it sounds like you'll need a dispatcher in a different language because that would be a long-running process).
This article is from 2013 and is not relevant anymore. Dozens of concepts useful even for writing desktop apps with PHP (I don't claim that it is the best choice) were presented in book "PHP Beyond the Web".
Not saying it's not possible: from where I am in 2020, long-lived PHP 7.4 processes still exhibit the described symptoms (memory leaks, even segfaults). In other words, tools for the job.
He means for example if you want to make database connection PHP has build-in function. But in Java you need few libraries. In one end it is one line code, in the other one it is several lines of code.
I agree PHP is vastly better than it used to be. It is also a bit more "batteries included" out of the box if you're doing things in a very very bare standard library/simple server sort of way.
That said, when learning web development, PHP, Python, JS, and Ruby are all very similar. You absolutely use a package/dependency manager of some sort, and they all have pretty simple startup with their major (similar) frameworks, whether Laravel or Django, Yarn or Bundler, etc., for their respective languages.
That said, there is one place where PHP is very different, and that is configuration. PHP still has a lot of configuration options that live in global config files, and a number of things that could be easily managed dependencies or are core in other languages are still extensions that need to be installed and enabled at the language level in PHP which seems worse from a "getting up and running" perspective.
I recently switched to working with Python over PHP. When I started working on this project no one on the team used a debugger nor knew how to set it up. VSCode became the easiest path for debugging so I use that but it doesn’t handle multi-threaded code well yet so it’s been a bear trying to debug. On the other hand. I added three lines of xdebug config to my PHP.ibi and I can remote debug the PHP stuff no problem. Granted it doesn’t have as much introspection as other languages it was still a much less painless process to dive in and see what the code was doing.
On the framework side, Laravel beats the pants off Flask or django IMO when it comes to deployment, asset build pipelines, queues and database migrations. Almost all of those can easily be configured with laravel and are very flexible. In Python world I had to do a lot of setup to get that kind of thing going.
Virtualenvs and pipemv and poetry weren’t terribly hard to configure but it took a lot more time to learn than PHP composer. Granted the ease of switching envs and versions in Python seems a lot simpler than PHP once it’s all setup.
If you're using Laravel + Homestead you can configure PHP versions on a per project basis in your yaml file and changing it just requires a vagrant reload
Python. I have been watching the PTVSD development very closely since 5.0 aims to address most of the problems I have. They just got spawn and fork support in recently so things should be much better now but it’s still pre-release and there’s a number of open issues left to solve. I didn’t have to work on threaded code in PHP so it may not have been fair to bring that up at all since it’s mostly irrelevant to the point that it was very easy to setup PHP debugging for my use cases and it was slightly more work to setup Python initially.
The improvements in the new version of ptvsd are around multi-process debugging, though, not so much multithreading, hence why I was curious. Multithreading was supported before VSCode even, going all the way back to PTVS 1.0, so if we still have any major issues with that, I'd definitely like to know!
Xdebug is great, but the setup process is not friendly. There's tools that try to automate the install process, but it's very far from having an OOB experience.
> for all other languages i know of, there is quite a process to get started
It's funny that you included javascript in the list when you can literally just type javascript code in an html <script> tag and open it in the browser that comes with your OS.
You quip at flask for requiring "command line experience" then talk about PHP's built-in web server that's also a command line tool.
And let's be realistic, if you're using php without a package manager, you're either no doing anything serious or you're reinventing the wheel, and you will need to get comfortable with the command-line sooner or later anyway.
I will say that PHP is probably the the most frictionless server-side web-development language to get started with, but it's not by a huge margin.
And considering that in web-dev you're gonna need to learn javascript anyway, I'd probably consider it to be the best introductory language.
> It's funny that you included javascript in the list when you can literally just type javascript code in an html <script> tag and open it in the browser that comes with your OS.
Let's be fair: you're going to be very limited in terms of the type of web site you can make with this approach compared with a PHP app via web server
Of course, such things are perfectly possible and for an image editor I'd consider in-browser js superior to anything but native apps.
However, consider this, you want an app that has to use a database, you can't store everything on the client or use things like Dropbox integration. Plenty of situations where you want that, but that just can't be done with clientside js without also making your database acces keys and encryption keys available to all. So all in all, it depends on what sort of app you want to build or form your course around
Or I just use node on the server side and write the server part also in js?
This was not about building anything sensible, but just to counter the point that js allows you less than php.
I think today the only big language with is a pain to setup is perl, java and sometimes python, the rest is just a matter of ecosystem, needs and personal taste.
>Let's be fair: you're going to be very limited in terms of the type of web site you can make with this approach compared with a PHP app via web server
Which translates to me that you have the impression that JS is limited in usage, which it simply isn't.
Things like webrtc and other node, changed the way JS can be used and for the things it can be used.
That script tag alone isn't going to do much without a backend.
JS frameworks (angular etc) have substantial learning curves for noobs and the language itself has at least as much WTF as php does. Then there's Typescript, Node, ...
Python & Flask are amazing but if you're taking your first steps at programming they do need a bit of effort to get up & running. What caused friction for me when I started out with Python was:
* V2 or V3, why, what ...
* pip / pipenv / virtualenv
* circular dependencies
You can start out with PHP using something like XAMPP + CodeIgniter MVC + PhpMyAdmin + FTP. Most people starting from zero should be able to build & deploy a todo list app in 1-2 days using this "stack". It's all old & outdated but as an introduction it works great.
> That script tag alone isn't going to do much without a backend.
When you're starting out, you're not going to do much in the first place
> the language itself has at least as much WTF as php does
Oh absolutely! My argument was mostly that for getting started, JS has actually less setup than PHP, not that it's a better language, or that it's a better learning language (although I happen to also believe both of those things but for different reasons, mostly because of the easily available REPL and debugger available in browsers, whereas debugging PHP is much more involved)
> Most people starting from zero should be able to build & deploy a todo list app in 1-2 days
and you can make a (local) todo list app in JS in the same amount of time without installing anything (because let's be real, setting up a database and web server, even bundled solutions like XAMPP can be a real challenge when you're starting out if anything at all goes sideways), and you can deploy it for free by just uploading the files to github from your browser. And if you feel that doing this without a framework is too hard there's a slew of tutorials to do it with jQuery (in the old and outdated category) or React/Vue (which don't have the added typescript complexity of Angular)
I am not saying that PHP isn't great to start with, but I feel like more and more JS can really compete in that space, and has some key advantages for further progression.
Ok. The focus of my argument was only on server-side development as php was the language of comparison... however as you mentioned javascript is easy to get started as well and more or less the only option for front end dev anyway (as typescript, coffeescript, etc are transpiled to js and webassembly has no direct dom access)...
PHP has its appeal with a install and then run script situation. Its simplicity of lacking any "project" structure (like what node.js has with project.json and .NET has with .csproj) or more complicated setup (Python with setenv) makes the first days of teaching a lot easier. Also the 1:1 mapping of urls and files is appealing.
However, after that first days, all of them rely on package managers (PHP, Node, Python, .NET, ...), custom routing and a structured project organization. This also explicit includes PHP.
You should try .NET Core (in your scenario maybe with ASP.NET Core Razor Pages). Its setup is very easy (dotnet new webpage; dotnet run) and normal projects rarely need the package manager. The only challenge is the sub folder containing the web pages ;).
I’m using mainly ASP.net Core for my projects but PHP is still simpler to get started with IMO. Microsoft’s framework does a lot of things, and a lot of magic involved which means sometime searching for hours in doc and stack. Another difficult thing is Startup.cs and all the magic middlewares whose declaration order actually matter.
That is right. And I agree. ASP.NET is already a framework on top. PHP is the best choice for immediate entry without explaining millions of concepts (like routing, middlewares, http, ...).
PHP uses composer as a package manager, which is quite simple to use and very easy to install (it's a phar archive, basically an executable zip file). And frameworks like Laravel can be installed with a single composer command. This is still very little setup to come to the same point.
The problem an educator has is the time from start till first success (from early happiness but also time constraint perspective). In the first lecture.
Important programming tools like Projects, Package Manager, Routing, separate view/model, ... are a delay in that timespan. They are all worth it and in most frameworks not too complicated. But each item needs time to explain.
Has it gotten easier to actually get running, without resorting to a pre-built docker image?
One of the biggest advantages of PHP is ease of actually doing the web server config, especially compared to dealing with an external app server along with its init script or systemd unit.
You'll eventually need a package manager. The only question is whether the language ships with one, the OS does, or whether you're on the hook to provide all package management by hand. I agree that PHP lets you go a bit farther without one, however.
> it seems that it doesn't matter what language one chooses
"there is a successful website written in X" does not mean that it is deemed appropriate or acceptable to use whatever you like. Anybody who has started a new project from scratch as a professional at a company can tell you it absolutely does matter what language one chooses, and if you opt for something non-standard or for whatever other reason deemed unsuitable, you will be corrected.
Php has built in web features and one doesnt need more than a php interpreter (considering the built in web server as well) to get started. For all other languages i know of, there is quite a process to get started (e.g. start with python flask one needs a package manager, environment variables, command line experience, ...). Php is a web native language and great for learning and getting started.
Considering professional development (https://en.m.wikipedia.org/wiki/Programming_languages_used_i...) it seems that it doesn't matter what language one chooses, various different stacks are used by the most popular websites..