9 ms·
“Hello, (real) world” in PHP in 2017
- iamdave 10y agoThis seems like a decent primer for someone who already has their heads wrapped around application development, but absolutely horrid for someone who wants to pick up a web language for the first time and create that first simple output. That first simple output IMO is critical for retention and engaging the language knowing exactly what you're going to get by looking at dirt simple code like echo hello world; at least it was for me as PHP was one of my very first languages The intent is well meaning in this "real world" hello world, but I feel like taking the espoused mentality in the opening paragraph, one is throwing construction tools at a toddler who asked for a box of legos for christmas. Curious what others think
- halfdan 10y agoYou do realise this article wasn't written as a beginner's tutorial but as a sarcastic view of modern web dev?
- sixdimensional 10y agoMaybe I am old fashioned and outdated. I don't know about anyone else, but it makes me pretty sad that the "modern" way as presented in this article is no longer simple and straightforward and has some severe dependency hell. Not that I'm saying the structure of modern web applications isn't needed and that we haven't advanced. Just that the overhead and knowledge required to set up a modern web application is crazy. I am working on a larger .NET web application in my day job... and it requires things like.. Typescript + typings files, Webpack/Gulp/Grunt/etc. and therefore Node.js and NPM, NuGet, .NET Framework, onion architecture, front-end framework (Angular, or React, or..), Entity Framework, multiple databases, web services/web API, ASP.NET MVC.. I mean, it's just crazy if you step back and think about it. Sometimes I long for the simpler "bad old days"? Oh well, back to my enterprise single page application framework-laden monster. DISCLAIMER: I know we're better off today in many ways, and maybe I'm just getting older and the cognitive load is higher.
- tluyben2 10y agoI definitely agree with you. And we are better off compared to the hack-hell it was when you were doing [0] (yes, that is still the tutorial), but I feel we are still finding our ways very much. If the progression from the old 'install and start developing and deploying' to the current brittleness and dependency hell is going to continue into the future, I will find something else to do :) [0] http://php.net/manual/en/tutorial.firstpage.php http://php.net/manual/en/tutorial.firstpage.php
- frou_dh 10y agoIt's usually not advisable, but I genuinely think classical CGI is beautiful mechanism for dynamically generated pages. It's a natural extension of Unix scripting: shebang'd scripts in any language, environment variables, stdout. Job's a good'un.
- coliveira 10y agoWhat is good for developers is bad for the industry. How else would they justify creating frameworks in different languages if all people are doing anyway is writing text to (F)CGI stdout? It is much better for the companies/groups involved to make people believe that there is something wrong with this and that they should really be using a "proper" framework.
- mike503 10y agoI don't mind this article as long as it's classified as satire.
- libeclipse 10y agoAhahaha I legitimately cannot tell if this is a sarcastic blog post. To me it just sounds like such a joke. It's quite confusing. I hope it's a joke...
- sixdimensional 10y agoI think this is a realistic reflection on the state of this area in our industry. It is both sarcastic/a joke and not a joke at all.
- endymi0n 10y agoPoe's law in full action. If for some reason this is not a joke, it's a pretty lousy tutorial, as for every single arbitrary framework/tool decision here, there's not a single rationale here but "because it's 2017". I'd absolutely prefer 1995's Hello World if it's just about saying "Hello World".
- krick 10y agoGenerally I would agree with you, but I think it should be taken with a grain of salt. "Hello World" is somewhat metaphorical concept, the ultimate goal isn't to show the label itself, but to show what is the amount of work required to produce some generic output without any business-logic involved. This means that it totally makes sense to use OpenGL or ncurses to show "Hello world" on the screen, even though they are obviously not necessary to do just that. It's just that they will be necessary for many other typical tasks we are considering. So, although I wouldn't really chose tools author choses here, so the "not-really-a-joke joke" is still largely opinionated, I have to admit that assuming AJAX and some kind of MVC-ish framework (even if it's a one of your own) on both back-end and front-end is pretty much a must for a typical PHP web-application.
- khedoros1 10y agoI don't think it's a joke, but I also don't think "tutorial" is the right word either. It seems more like an illustrative commentary on the state of the webdev industry.
- Entangled 10y agoCall me old fashioned but I prefer my code naked, plain php and postgres, nothing else, not even JS. So for me, echo 'Hello world' is good enough.
- travisjungroth 10y agoUsers overwhelmingly prefer some amount of client-side interaction, so how do you do that without JavaScript?
- paulddraper 10y agoHTML Links, text boxes, selects, radios, checkboxes, buttons, forms, and content.
- rabidrat 10y agocss :hover with hrefs to fast-loading pages can give the illusion of interactivity without any javascript (or even server processing, if the whole site is statically-generated).
- martin_a 10y agoMost people don´t know how to build this because their X MB JS framework just slows everything down.
- robryan 10y agoDepends what you are building. I have certainly had more frustration using single page or collections of single page apps. It is very rare that they get the back/forward button handling and refresh handling exactly right.
- tonyedgecombe 10y agoAre you sure about that, I don't think many of the users I know could tell the difference.
- acomjean 10y ago
- mndewitt 10y agoUsing React, TypeScript, and Webpack in this context is ridiculous. Use tools that solve the problem at hand, not just because someone else is doing it...
- dheera 10y agoBut we're now using "Agile development", so I guess we have to use those things.
- buro9 10y agoThe only thing missing from projects I've seen up close is that the value would be selected from the database using a stored procedure.
- CCing 10y agoOr GraphSQL!
- z92 10y agoJust write "Hello, world!" in a file without the quotation marks, and nothing else. Save, then run. Will print what you asked it to. Default in PHP is to output the bare text. Unless you wrap it in special markup '<?php'. That's an unique feature in the top languages.
- camus2 10y ago> But each dispute has an argument in favor of PHP — it’s easy for beginners. To my mind, this argument isn’t valid anymore, which is exactly what I was trying to say in this article. It's still is easier AND cheaper to deploy a Hello World in PHP than a Hello World in any other language. You can get a cheap Apache/PHP hosting for $2/month, use SFTP a get a working app in minutes. The default PHP distribution comes with a lot of extensions. The problem is that PHP doesn't help a beginner graduate from a basic webpage to a secure and robust application without having to download a complex framework and meddle with configuration files. IMHO by the time you are tempted to use Symfony you might switch to Java or ASP.net directly. If PHP was really beginner oriented, it would actually do everything it could to use the most secure defaults for every feature, like templating, or sessions. Microsoft attempted to do that with WebPages, which is kinda what PHP should have been if it was really intended for beginners. WebPages mostly use secure defaults. While it doesn't prevent spaghetti code it makes having to rely on a complex framework unnecessary.
- webreac 10y agoa C1 or VC1S at scaleway is 3.6€ per month. This gives you total control to install anything (nodejs, ...)
- seanp2k2 10y ago...and now you're a sysadmin, with a whole new world of exciting career opportunities. And if you can also write bash scripts and spell Jenkins, welcome to devops! The point is that if you're 13 years old, somewhat crafty, and just want to make a website that puts text on dank memes using ImageMagick to impress your friends, PHP and $3/month hosting with a friendly alligator that you can show to your mom to get her to put her CC in without thinking you'll get hauled off by a black helicopter...will get you to done quickly without having to read a foot of O'Reilly books, 20 DigitalOcean tutorials, 57 Wikipedia pages, and 118 StackOverflow answers. Spaghetti PHP on shared hosting written by copy/pasting comments from the PHP docs and SO is a fantastic gateway drug for teens who end up being great developers. I love it.
- xchaotic 10y agoA bit like the other submission on learning JS in 2016. I find that I am getting dragged down by complexity. Even simple tic tac toe game that I was planning to write in vanilla js took me via jQuery, npm, Firebase etc. Sure its production ready but I just wanted to write something for fun. Wasn't really fun.
- krapp 10y agoWe can't have fun anymore. Web dev is serious business. No one even writes javascript anymore, they compile it from Haskell or whatever. That's how serious it is.
- oddlyaromatic 10y agoI'm curious, how did you find yourself taken to those technologies? What made you feel like you couldn't achieve it in vanilla JS?
- CCing 10y agoSometimes I miss the old good days with PHP mixed in HTML. Maybe wasn't the best solution but it worked...and was fast too.
- krapp 10y agoI don't miss having to manually add includes and update dependencies with FTP. I don't miss htmlspecialchars or mysql_real_escape_string, I don't miss running everything in the webroot, I don't miss having to switch contexts between PHP, HTML, Javascript and CSS all mixed in one file. The good old days kind of weren't that good. The simplicity of bare PHP was great for cowboying up sites in a hurry, but it's not a system that handles complexity well.
- mythrwy 10y agoHaving had to find and fix a bug in a very long page like that recently I can definitively say I don't. Horrible. Granted the person who wrote it obviously didn't care but that setup was awful for anything of any size.
- CCing 10y agoYou can write bad code(not modular) with every language... If you use some include() in php, you can avoid long php/html pages... What I really miss is that was very fast "GET SHIT DONE" with PHP.
- seanp2k2 10y agoIs non-modular code always necessarily bad?
- krapp 10y ago>If you use some include() in php, you can avoid long php/html pages... In my experience, you just get long PHP pages including other long PHP pages, globals defined in one and used in others, included files that contain nothing but HTML, and other madness. You can certainly GET SHIT DONE in PHP with a bit more coherence. Composer, with its autoloader and a router (probably nikic/fastroute) won't get in your way, your code will be more organized, modular, and lightweight, dependencies can be managed, etc.
- iDemonix 10y agoNailed it. I love PHP and it's still my main language, but the reason so many projects never get completed is because of this. Really I should just accept that for an MVP, Laravel and a static front end with some old school jQuery where required is fine.
- CCing 10y agoSorry but if you love PHP and use as your main language, why you don't complete any sideproject ? I don't understand your statement.
- iDemonix 10y agoI do complete side projects, but I don't complete more than I complete. Often it's because trying to balance multiple projects when each is using multiple frameworks in different ways becomes a massive headache, things get paused and then canned because now there's newer buzz-word frameworks to use!
- smacktoward 10y agoSide projects are natural places for programmers to get lost in this kind of bike-shedding/yak-shaving/etc., since they're not under the same kind of "this needs to ship on Tuesday or I lose my job" pressure that work projects are.
- rwallace 10y agoAnd in fairness, one of the better reasons to do a side project is to get up to speed on some fashionable technology so you can get a better job; that may well be of more value to you than the nominal deliverable, in which case it could make sense to prioritise it.
- okket 10y agoThis is a bit like $ echo 'Hello World!' which if, you think about it, requires a kernel, multitasking, driver independence on various level, many drivers, memory management, possible resource accounting, binary api, dynamic linker, interpreter, etc, etc, etc. All (or at least most) of this seems overkill if you just want to print out 'hello world'. But it makes total sense if you want to do a little more complex stuff.
- adevine 10y agoI think that's kind of the point, though, that OSes and shells have gotten to the point where all that complexity is hidden behind an easy installation. With modern web frameworks, all the "guts" are still fully exposed, warts and all. It kind of reminds me of the state of Linux in the mid-late 90s, where you'd have "install fests" with a roomful of 25 people and it took a whole day to get Linux installed on your machine (and your sound still didn't work, that took another afternoon).
- lohengramm 10y agoCoincidentally I recently began a new project involving a user-facing PHP app, and even though I have enough ES6 + webpack + react blablabla experience (and some angular, but I didn't particularly enjoy it), I decided to just go with good old synchronous requests. It makes things easier and, in this case, development time is key.
- DanHulton 10y agoSo many people not getting the joke here. This article is a send-off of the idea that PHP is "just easy" anymore, but frankly, misses its shot. Of course it's complex when you introduce complexity. So is anything by definition. If you don't want to do complex things, you're fine. But if you want to have a database, have a framework abstract away the truly dangerous and boring shit, use a modern, type-safe version of Javascript, write CSS in something approaching a maintainable fashion, and deliver a responsive, reactive site, you'll have to do something like this, regardless of language. Also, the author neglected to set up database migrations, to say nothing of a Dockerfile.
- unscaled 10y agoAll true. But OP was never trying to argue that PHP is more complex than other language, but instead claimed that once you get to the point of requiring complexity, PHP doesn't get to have the "it's braindead simple" advantage anymore. To quote: --- Disputes like “Why do I need PHP if there’s Java?” have become more frequent nowadays. I don’t know who’s in the right, Holly Wars are tricky. But each dispute has an argument in favor of PHP — it’s easy for beginners. To my mind, this argument isn’t valid anymore, which is exactly what I was trying to say in this article. A novice programmer will have to learn lots of new things, as well as write tons of configs: frameworks (very similar to java frameworks), databases, linux, shminux, JavaScript with all its baggage, http-protocol, various tooling and many more. Even if it’s not SPA.
- jakon89 10y agoWhat is the point in writing blog posts like this?
- ponyfleisch 10y agoThe author makes it clear at the end of the article. The claim that PHP is "beginner friendly" is bogus now because any serious development in PHP is full blown enterprisey software engineering.
- vectorpush 10y agoI get that this article is satire, but I think the deepest (perhaps) unintentional insight presented by the author's veiled criticism is that the justification for using these tools is presented as "it's 2017" and not as a solution to any particular problem. The issue isn't the 2017 ecosystem, the issue is the 2017 programmer's deference to vanity instead of engineering. All these individual tools exist for a reason, and if your project is already functioning to specification without the use of these tools, you shouldn't be using them; doing otherwise is the developer's fault, not the tool's or the ecosystem's.
- rosser 10y agoIt's called "résumé-driven development."
- sixdimensional 10y agoAnd sadly, in the race to stay competitive, it's all too common.
- Spivak 10y agoWell yeah, why would you do anything else? When recruiters and job postings are mostly concerned with what languages and tools you know over software development ability and computer science knowledge why would you voluntarily make your life more difficult?
- rosser 10y agoI believe the term you're looking for is "middle ground".
- navs 10y agoMight explain why I don't get many recruiters attempting to contact me. Back when AngularJS was the big thing, I'd get bombarded on LinkedIn. Now, having only non-commercial experience with React and refusing to list it on my resume, I'm mostly ignored. Now are recruiters to blame or the companies that hire them?
- robbiewxyz 10y agoEveryone's trying to take this literally as the "right way to display plaintext" in modern PHP. In that sense, it is absolutely absurd. But if the idea of a "hello world" is to learn the basic boilerplate that you'll need before you start implementing real features, unfortunately for us web developers, this quite accurately represents the minimum before we can even start implementing business logic. With the baseline expectation for a lot of modern SPA-type applications including caching scripts, client-side routing, server-side rendering, working offline, supporting IE9 to iOS to Firefox and all the quirks in between, etc it really is getting to this point. I wish like nothing else that most of this could come out of the box so "hello world" really was a one-liner, but that just doesn't seem to be the reality that 2017 webapps live in.
- m_fayer 10y agoThen again take a step back and look at what's being achieved. You are delivering, nearly instantly, a sophisticated and responsive fat client application to the user without any installation process. This fat client is running in a nearly universal and quite safe sandbox that is provided by several vendors across different os's, form factors, and architectures. With a good amount of backwards compatibility. Backed by a backend that's almost infinitely scalable. And developers are constantly feeding new features into this system without bringing it down or interrupting anything. From that perspective, you would expect the tooling and stack to be complex. We really are doing way way more than we were in the "old days." "Write once run everywhere" has arrived and we're doing it, it's just not as simple as it sounds.
- Klathmon 10y agoAnd to just pile on with this comment, "run everywhere" means much more than it ever did. This isn't just the big 3 desktop OS's, but laptops, tablets, phones, TV's, game consoles, car navigation units, hell my goddamn watch can run websites now! X86, ARM, SPARC, PPC, it doesn't matter. And on most of those platforms, you have more than one choice of browser. It's a level of cross-platform that really only simple C programs can even begin to reach. And it's not exactly simple to setup that environment from scratch either.
- kuschku 10y agoWe’ve gone full circle. Truly look at the PHP code in this article, the JS dependency hell here and in the recent JS article. Look at the code. At the environment. At the libraries. Who isn’t reminded of what Java looked like years ago? We’ve come full circle. ------------------------ Now, if one asks why this is, the answer is pretty simple – enterprise products. To build software of a certain scale, certain technology, patterns, etc are required. These are what we see here again – ORMs, complex dependency systems, complicated frameworks, etc. One might wonder why people even write PHP and JS nowadays, if Java is still faster, JS and PHP are now equally complicated, and Java ported all of the advantages of the others. And, in fact, the Play Framework (which supports Java and Scala) is growing. At the same time, Google’s go is copying the same mistakes Java did in the beginning, with almost all new methods in the standard library taking interface{} – the equivalent of void* or Object, and a simplistic typesystem. ------------------------ Why do we, as a profession, create new tools for a new purpose, then force them to adapt to another purpose, until they’ve become identical to the tools we tried to replace?
- tannhaeuser 10y agoWhy is the "enterprise" the culprit? The things you describe have more to do with generational churn, abusing the web as a desktop replacement, and developer's desires to always use the latest stuff as a stepping stone for the next gig, or maybe to convince themselves they're avantgarde when in reality it's mostly boring stuff.
- kuschku 10y agoBecause, once you start working with complex systems, you’ll require complex frameworks. That influences the way the entire language goes.
- ams6110 10y agoThere isn't much history taught. So each generation makes the same mistakes over and over again.
- tonyedgecombe 10y ago
- partycoder 10y agoI am going to leave this here... https://en.wikipedia.org/wiki/Rule_of_least_power https://en.wikipedia.org/wiki/Rule_of_least_power If you enjoy overengineered code, check: - Fizzbuzz Enterprise Edition: https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris... - Fizzbuzz in Tensorflow: https://github.com/joelgrus/fizz-buzz-tensorflow/blob/master/fizz_buzz.py https://github.com/joelgrus/fizz-buzz-tensorflow/blob/master...
- Ambrosia 10y agoRight. Let's just delete everything and go back to a world where even more websites are packed full of vulnerabilities, written in spaghetti PHP!
- tommorris 10y agoI expect adding yet more lines of code will reduce vulnerabilities.
- wernercd 10y ago> Summary: Disputes like “Why do I need PHP if there’s Java?” have become more frequent nowadays. I don’t know who’s in the right, Holly Wars are tricky. Who is this Holly and why are we starting a war over her? All this talk about "Enterprise over engineering", is all this needed, tool-overload-hell, etc... and I just can't stop thinking about Holly and how to stop the war over her...
- nillawafer 10y agoOnce you've spent all this time setting up a NodeJS stack.... why use PHP at all? Ie. just use Node for the API/Server, you're already setup, and the stack would be 100% one language.
- seanp2k2 10y agoExcept e.g. React and Express are so different and work on such vastly different domains that them being in technically a similar VM is more or less inconsequential. They're two entirely different disciplines and have different build pipelines, deploy pipelines, etc. I don't see much benefit in having them in the same language. One thing does DOM state while the other does ~play in traffic with libuv. Like hey it's nice that this OS kernel is implemented in C, good thing I am also writing my GUI in C. Idk, maybe it's a boon for some, but I've tried it and don't really see the big appeal...except for Meteor, because if I'm writing both my UI and API in the same * language, why in the would I need to write my models in both places and maintain them separately. But meteor has problems too, I just always thought it was neat way of doing something that would only be possible ("easily") when using the same lang on both sides.
- megous 10y agoHello world! in PHP is simply: Hello world! People forget PHP is still a template language for the web.
- trhway 10y agowell, it is our job as programmers is to waste ... err ... utilize all that hardware power/bandwidth that Moore law has been showering us with...
- quickben 10y ago'old' vs 'modern': I run a search engine. It is big enough that it needs drives, caches, firewalls, VMs etc. The front end is php. No classes, no phpadmin, etc. Just pure vanilla php. Sometimes I tail /var access logs. People try all kinds of urls routinely fishing for weaknesses. It's 2017. It is slow to code and keep the attack surface that minimal. 0 intrusions so far.
- ponyfleisch 10y agoWhile reading i was thinking "..but that all makes sense for any project that's larger than a few hundred lines.." and thought the author was just ignorant and needlessly cynical. But at the end of the article, he makes a good point: Disputes like “Why do I need PHP if there’s Java?” have become more frequent nowadays. I don’t know who’s in the right, Holly Wars are tricky. But each dispute has an argument in favor of PHP — it’s easy for beginners. To my mind, this argument isn’t valid anymore, which is exactly what I was trying to say in this article. The notion of PHP as a beginner-friendly language has in my opinion been a harmful one for a while now. There are still people writing old school PHP apps, and there is the (mildly displeasing) wordpress ecosystem. But for anything serious, Symfony is invaluable. And the gap between old school PHP to modern PHP is almost the same as the one between old school PHP and Java/Spring/Hibernate, which is kind of what Symfony/Doctrine is cloning anyway. Plus if you do Java, you don't get the stigma of being in the same category as a professional wordpress template tweaker.
- raziel2p 10y agoI like to argue that you can start off using PHP as a scripting language with a single index.php file, then maybe learn to use some of the simple frameworks like Slim (though even that has become more complicated recently), then move from that to Symfony or the like. This is a point the original author misses. If you introduce beginners in PHP to Symfony and SPAs from the start obviously they're going to have a bad time.
- ponyfleisch 10y agoI'm not convinced that this approach flattens the learning curve significantly. The concepts are different, and when you're at the end of that journey and look back, you'll find that you spent a large amount of time unlearning things. That is if you ever get there. It's easy getting stuck on local maxima when avoiding steep learning curves. In other words, old school PHP and modern PHP are two vastly different beasts with few commonalities. There is no way past learning the basics (OOP, patterns, proper architecture), by deferring that in favour of an easier start you're only lengthening the journey.
- methodin 10y agoI enjoy that the concept of Hello World engulfs a full-stack deployment. Every one of these dependencies has a Hello World and the fact that people might not be aware of them is a real problem.
- Girlang 10y agoIt's still way too complicated to make a simple non-static website, but we've made things a lot simpler at our company with Elm.
- hugodahl 10y agoThen, come peer code review/pull request by a senior/lead person, will be declined with the comment <? echo "Hello, overengineered world." ?>
- bikamonki 10y ago99% of real-world apps out there could be implemented with a BAAS and some simple JS MVC framework (good ol' BackboneJS in my flavor, if not jQuery fancy). I am not talking about building million-user-base facebooks and twitters, I am taking about a fuckzillion apps with a dozen at best concurrent users that will thrive in Firebase's free tier, a damnzillion worpress sites that never-fucking-ever get updated and would do just fine with good ol' static html, forever spared from bitcoin ramsomware. Simply put: we forgot how to be engineers (the right solution for the problem). We are all Zuckergified into the fucking hype. Aren't we? We forgot that it is WE the experts that should tell clients how to solve their damn problems not just echo some buzz words so we get the damn contracts. This post is NOT satire. It is the very state of current affairs.
- seanp2k2 10y agoFWIW the Wordpress situation and specifically my personal site getting hacked even though I was a sysadmin working in hosting at the time are why I love static site generators. Moveable Type was always amazing and scaled with traffic literally 100x as well as Wordpress out of the box (Varnish and W3 Total Cache can help if you ever need it, but again "out of the box"), so I'm happy to see that things like Jekyll and Hugo are trendy. The fundamental idea behind SSGs just makes so much sense to me; optimize it for viewing (in terms of computational power spent on serving traffic), which it'll be doing many more times than it will be created. Why generate a page on each visit when that page will be exactly the same until the post gets updated? I understand that many WP sites are much much much more than blogs (like shopping carts, ooh god why), but that's a different conversation entirely. Wordpress (and any dynamic CMS) is like having a library full of whiteboards with the contents of the books written on them, with about the same potential for vandalism.
- _nalply 10y agoWhen I first read that I saw the nice girl with the red T-Shirt and thought, wow, the simplest way of writing Hello World in PHP is literally Hello World (no <?php and so on). Of course this would be broken HTML but first it displays, and second you could configure the web server to send Content-Type: text/plain without charset parameter because YAGNI.
- deleted 10y ago[deleted]
- wanderr 10y ago"You can’t build a decent modern application without frameworks." Bullshit, especially on the PHP / backend side. It's 2017, we should know how to avoid over engineering simple things.
- guillem_lefait 10y agoWhat about internationalisation ? You have to add i18n.