22 ms·
I wrote a lot of PHP from 1999-2008. First as a hobby, then professionally. From 20 LOC guestbooks to payment gateways used to process millions in payments. It
by elric 6y ago
I wrote a lot of PHP from 1999-2008. First as a hobby, then professionally. From 20 LOC guestbooks to payment gateways used to process millions in payments. It wasn't until recently that I was sure I'd written more code in any other language than PHP. These days I'll occasionally poke around with it or patch a bug, but that's about it.
Is it a perfect language? No. But which language is? (I can hear the Lisp crowd grumbling.) It's fast. The only ceremony you need to write executable code is the <?php tag. It has a very rich standard library -- even if some of the function names make me want to stab people.
My only real gripe with PHP is the annotation syntax. Yikes. Stuff that's in comments SHOULD NOT AFFECT RUNNING CODE. Who came up with that?
PHP has taken a lot of flack over the years. Mostly from people who never really worked with it. A lot of the criticism really should have been aimed at certain PHP developers, rather than the language or the community at large. PHP's low entry barrier is a blessing, it's how a lot of developers were introduced to programming. It's also a curse, because a lot of very inexperienced programmers managed to become prolific at getting code out there, code which was ugly, bug infested and a security nightmare. But it's not fair to attack a language over its inexperienced users.
- hanikesn 6y ago> My only real gripe with PHP is the annotation syntax. Yikes. Stuff that's in comments SHOULD NOT AFFECT RUNNING CODE. Who came up with that? It's a workaround to copy Java's annotations which IIRC also came from javadoc. PHP-8 is adding proper annotations as well. In general being able to add parseable meta information to your code can be quite useful.
- purerandomness 6y ago> Stuff that's in comments SHOULD NOT AFFECT RUNNING CODE. To clarify, comments never affect running code in PHP, ever. What's often done however is that tools like ORMs, or web frameworks offer a 'compile' step that parses these annotations (just like it's common in Java) and dumps a PHP file that maps things in the annotations into actual PHP code. For example, you can use it in Symfony to wire routes to handling functions in controller classes; or in Doctrine to help the mapper wire Entity classes to database tables. If you don't like the idea of preprocessing annotations, you can totally not use them and configure everything using external YAML/XML files.
- elric 6y agoYeah I worded that poorly, but once I went full on caps I decided to leave it, ahem :/. I get the idea of a compile step, and that's totally fine. But these annotations are commented out. It's very icky to be using them for anything other than documentation -- which is what comments are for, after all. Java's annotations are a bit different. Sure, the compiler does things with them -- the runtime does, too --, but they're syntactically part of the language. In PHP, they're kinda of not. Not yet, anyway.
- slifin 6y agoIs a heftier compile step totally fine? The biggest difference between PHP and Java in my mind is that you start Java and pay the compile cost on server start, in PHP you pay the compile cost on every request, frameworks and language features increasingly hide this future cost in caches but caches are one of the two hardest things in computing and often act like pushing things under the carpet, why optimise the compile? It's under the carpet As we move closer and closer to Java's model, we get further and further away from that quick PHP feedback loop of, make a change press f5 see the changes immediately and quickly Which puts us further and further away from the kind of ideals that Bret Victor mentioned in his very good talk inventing on principle: https://youtu.be/PUv66718DII https://youtu.be/PUv66718DII which to quote: "Creators need an immediate connection to what they're creating." Inevitably this is coming and is already here but we should recognise what we've lost
- agustif 6y agoMeanwhile with something like NextJS/TypeScript/React you can just enjoy instant reloads without ever caring about F5 again The more languages the better IMHO though
- purerandomness 6y agoDid you just deliberately redefine 'reload' just to incite a flamewar, or do you really not know what's different in your example?
- doiwin 6y agosome of the function names make me want to stab people What would be an example? My only real gripe with PHP is the annotation syntax What do you mean? Afaik there is no "annotation syntax" in PHP. Could it be that you confuse what certain frameworks and IDEs do with PHP, the language?
- Karunamon 6y agoFunction names are rather inconsistent. get: gettype get_class str: str_ireplace str_pad str_repeat str_replace str_shuffle str_split str_word_count strcasecmp strchr strcmp strcoll strcspn encode: base64_encode quoted_printable_encode session_encode rawurlencode urlencode gzencode php: php_uname php_sapi_name php_logo_guid phpinfo phpcredits phpversion htmlentites: htmlentities html_entity_decode to: stream_copy_to_stream strtolower strtotime strtoupper unixtojd 2: bin2hex deg2rad hex2bin ip2long long2ip nl2br rad2deg
- danaris 6y agoI have heard—and I do not recall the source for this, so it may be incorrect—that when PHP was originally being written, the hashing algorithm for function calls used the length of the function name as its primary key. Thus, making each function name a slightly different length made the code run faster. Of course it would've been nice if, at any time in the past 20 years, they'd gone back and standardized those function names (possibly also adding some kind of backwards-compatibility shim for people who absolutely cannot update their ancient codebase with global search-and-replace), regardless of whether the story is true.
- johannes1234321 6y agoThat reasoning is true to a third. Length as hash was indeed a thing in PHP/FI 2. Second third to the reason is that PHP often takes names from underlying C libraries. strlen is strlen since that's the C name etc. Third third reasoning is that early PHPade it easy to contribute. You had a need and a patch - a few minute Slater it is in. Nowadays there is more of a debate and vote before things are added (in my personal opinion too much emphasize on voting, but, well that's how things go, some day the process will be relaxed again ... and strengthend ... and relaxed) Cleaning this up isn't trivial. There eis sooooo much code written already. There are sooo many tutorials, books, articles, magazines, videos and muscle memory making a change hard, even ignoring that for many things there is no single truth about what is best. From time to time some modules might see replacements with more streamlined APIs (i.e. Maybe someday one figures out what a good and practical Unicode aware string library might be, which might replace the classic string mess) but those are multi year things.
- TheDoctor0 6y ago> My only real gripe with PHP is the annotation syntax. Yikes. Stuff that's in comments SHOULD NOT AFFECT RUNNING CODE. Who came up with that? That will change in PHP 8 with the introduction of attributes (https://wiki.php.net/rfc/attributes_v2 https://wiki.php.net/rfc/attributes_v2).
- simias 6y agoEvery time there's a story about PHP there's a comment like yours, and then in reply there's a comment like mine: Yes it's perfectly fine to use PHP if it's a productive environment for you. Of course it's possible to write good software with it. Of course a skilled developer will manage to do great things with sub-standard tools. Many extremely popular websites were and even still are powered by PHP, that's undeniable. But that doesn't mean that we should absolve PHP of all its many, many design errors over the years. There were for a long time many fundamental issues with PHP as a language that didn't exist with its peers. The language was not so much designed as it was cobbled together by amateurs starting from a half-backed templating engine. I'm not saying that to hate on PHP, I just believe that it's important to learn from your mistakes if you don't want to end up reproducing them. It's important to acknowledge the many failings of PHP even if many of them are now ancient history. This revisionist stance that there was never anything really wrong with PHP and it's just Lispers who hated on the language because it was popular and beginner-friendly and they didn't know what they were talking about is simply, factually, provably untrue.
- castis 6y agoNo one is claiming that PHP is and/or was without fault. The sentiment is that we built things that worked despite them.
- ragnese 6y agoThat's not being fair. There are many comments on HN of people saying exactly that PHP just isn't bad. The grandparent reply even says: >My only real gripe with PHP is the annotation syntax.
- pjc50 6y ago> The only ceremony you need to write executable code is the <?php tag This is a really underappreciated aspect to development in general and web development in particular. There are (or at least were) an awful lot of "shared hosting" providers which are cheap, convenient, and run PHP and CGI only.
- TedDoesntTalk 6y agoColdFusion, Java Server Pages, and other languages copied this syntax. I don’t see it anymore except with php. Does anyone know of any other languages still in use that have this?
- freehunter 6y agoYou can do it in a lot of templating engines like Jinja2 and ERB.
- cutler 6y agoThat's not comparable with PHP as ERB files are not executable by default within the document root.
- brlewis 6y agoI thought the comment was talking about PHP already being installed, so you could just start using it.
- pjc50 6y agoAs the other comments say, it's not what the syntax is but the way it managed to get itself integrated into the webserver, originally via Apache mod_php. (mod_perl and even mod_tcl existed but were nowhere near as popular)
- lowercased 6y agoI believe mod_perl had the 'benefit' of persistent/shared state, which meant multiple users might conflict with each other (via shared memory, IIRC), and the mod_php - while it kept an interpreter bundled in each apache process - didn't leave anything around after a request.
- throwaway6734 6y ago>My only real gripe with PHP is the annotation syntax. Yikes. Stuff that's in comments SHOULD NOT AFFECT RUNNING CODE. Who came up with that? Agree. The first time I ran into this, I was completely confused as to why my code wasn't running as expected. Then I noticed the strange formal structure of the comments, made changes there, and voila. I don't understand why that feature wasn't implemented as decorators or some kind of function code. If anyone has any resources/thoughts on why this path was chosen, I would be interested in seeing them.
- bkanber 6y agoIt's pretty terrible. ORMs like Doctrine use annotations because their philosophy is that a data mapping class should be a pure class that you decorate with annotations. I personally hate that approach and have had no issues avoiding this path over 20 years of PHP development.
- eeZah7Ux 6y ago> PHP's low entry barrier is a blessing That's the error.
- elric 6y agoWhat's up with that elitist attitude? Are you saying that people shouldn't be able to write code unless they've first how to do it properly?
- NateEag 6y agoI think he's saying that PHP enabled a lot of people to build disastrously broken systems to do jobs they had no idea how to do. I worked for a shop in the past that had this problem in spades - huge ColdFusion and PHP ecommerce sites that were a gigantic ball of horrifying security and functionality failures, started by people who taught themselves how to program on the job because someone said "we should sell our stuff on the web". I guess the world is probably net better for those sites existing, even as they are, but it feels like PHP could have done a better job of helping learners not shoot themselves so violently in the foot.
- eeZah7Ux 6y agoNo, obviously. They should not be able to have that code uploaded into package managers without any form of peer review and vetting. Academic journals, book publishers, Linux distributions do vetting. Reputable journals, publishers, distros are more strict than non-reputable ones. Universities do exams. Companies do interviews. Why is it acceptable that some software communities have zero standards?
- eeZah7Ux 6y ago> A lot of the criticism really should have been aimed at certain PHP developers, rather than the language or the community at large. Communities should be kept responsible for setting quality standards or failing to do so.
- JAlexoid 6y ago+10000000 PHP has been horrible at maintaining the core library. The core library is a guide for developers, as to what their code should look like. (Brian Goetz goes on a long talk about the fact that all of your code is an API, even if you don;t mean it to be) That's why every time I chastise Scala developers and Martin Odersky for symbolic operator overloading. The guy talks at length about how it's wrong to abuse the symbolic operator overloading in creating unintuitive operators.... and then introduces :$#@%$%$%:;:/ operator to create a list.
- ragnese 6y agoWhile I agree that PHP does have pros as well as cons, I find it disconcerting that I've read MANY assertions here on HN, that PHP detractors just haven't used it very much or are mostly complaining about things like bad standard library function names. I've used PHP in earnest. It and JavaScript are tied for worst programming languages I've used. JavaScript gets more of a "pass" from me because I'm just not a dynamic-typing fan and I'll admit that it might be less awful for someone who enjoys/prefers Python or Ruby or whatever. PHP, on the other hand, is basically just worse-Java. And Java isn't a great language, either. The built-in PHP array is a constant source of frustration. Keys are sometimes strings, sometimes ints. And you don't always know which it is! This makes working with the array_* functions cumbersome at best. The fact that you can't typehint everywhere also sucks. No generics sucks. No threads sucks. No (real) async sucks. Globals suck (including different language behavior based on a config file on your machine...........). It's just not a strong language. And I'm super-tired of hearing "it's not the tool, it's the user." There is such a thing as a shitty tool. And just because some human somewhere CAN write working code in Brainfuck, does NOT mean that anybody SHOULD. I'm similarly tired of "all languages have warts". Do I even need to actually explain the fallacy there? On the other hand, I agree 100% that PHP's deployment story is awesome! But is that because PHP did anything useful, or because Apache and Nginx support PHP out of the box?
- nobleach 6y agoJust like I tell people that buy cordless drills at Harbor Freight, "sometimes it IS the tool". Does that mean you can't build fast, meaningful, cool things with it? Of course you can. But, the deeper you get, the more problems you'll have to solve with weird esoteric knowledge. I'll agree with all of your points on horribly inconsistent and broken language features. I get that people that have grown up with the language, or folks who have used it full time for years, don't see these blemishes as that big of a deal. But to newcomers, or folks from other languages, it's an affront. I hate to pile on an old, worn out issue but, as a language designer/implementer, the moment you start working on `mysql_real_escape_string()`, a huge warning bell should have gone off! I'm fine if people want to question my competence in writing code. It happens all the time on HN. I've been at it for 20 years... so some rando telling me that I don't know what I'm doing is pretty common. What we find in PHP though is quite a bit of tribal/tacit knowledge. And it's wrong to blame the user.
- ComputerGuru 6y ago> It has a very rich standard library Yet I still have to define startsWith() and endsWith() any time I touch PHP code... (More importantly, PHP is the one language I can never write from memory without referencing the manual for each and every function call because of how inconsistent it is. Eg Sometimes $haystack is the first parameter and sometimes it is $needle.)
- SergeAx 6y agoThere was an RFC for that, but it was voted out: https://github.com/php/php-src/pull/2049 https://github.com/php/php-src/pull/2049
- AegirLeet 6y agostr_starts_with() and str_ends_with() are coming in PHP 8.0.
- JAlexoid 6y agoThat would be str_starts_with() and strendswith(). &$ing up functions names is a feature of PHP.
- potta_coffee 6y agoThis is my problem with PHP. Python for instance has it's own issues, but after coding in Python for awhile I can just guess the interface of various methods etc and be correct almost all of the time. PHP in comparison is so egregiously inconsistent that I have to reference documentation constantly. Python, Go and even Javascript are light years beyond PHP quality-wise (I'm comparing to those 3 languages because they're the ones I use daily right now).
- brlewis 6y ago> PHP has taken a lot of flack over the years. Mostly from people who never really worked with it Detractors of PHP were pretty quiet when this first hit the front page. I think things might have stayed quiet without this first salvo being fired.
- CM30 6y ago> The only ceremony you need to write executable code is the <?php tag. This is a hugely underrated benefit of PHP overall, and arguably the one reason better designed languages won't replace it for web development purposes. You don't need a command line or SSH access or server management knowledge or many resources/A VPS or dedicated server or well, pretty much anything. It's also why about 99% of fancier, more up to date alternatives to software like WordPress or Media Wiki or [various forum scripts here] don't catch on too. The older software can be installed/maintained by people who aren't very technical, whereas many attempted replacements require you to be a developer/server admin to understand the install process. Anyone who truly wants to replace/be rid of PHP should come up with a language that works in much the same way.
- omnimus 6y agoWell even bigger reason might be the overhead of php apps. PHP is poormans Lambda. It allows many apps to live on same server and only take resources they need. It's not pretty but this allows shared hosting to exists. Those power big chunk of the content of the internet.
- guggle 6y ago> My only real gripe with PHP is the annotation syntax. Yikes. Stuff that's in comments SHOULD NOT AFFECT RUNNING CODE. Who came up with that? Hey, think about it: in Python we have type annotations that are in code, not comments, and yet THEY DON'T AFFECT RUNNING CODE ! ;-) > But it's not fair to attack a language over its inexperienced users. I wrote PHP code in roughly the same period as you. Before a certain point, PHP actively promoted bad practices which was not helpful to the inexperienced users.
- tannhaeuser 6y agoWhile <?php ...> and its equivalents for ejs, asp, or jsp are useful and a defining characteristic of PHP, it is implemented carelessly and prone to injection attacks. Using an SGML processing instruction for integrating scripting into markup languages is only a means of last resort when SGML has much better, type-safe expansion and processing features. "Modern" PHP leaves embedded PHP more or less behind in favour of Java-like frameworks, custom template engines, and other code-heavy approaches. However, the more PHP becomes like JS, the less there is a reason to use PHP over JS (which is at least standardized and has an extremely rich ecosystem) IMO.
- cutler 6y agoHow is PHP becoming like JS?
- dreamcompiler 6y agoI'm firmly in the Lisp crowd. I loved to hate PHP until I was forced to dig into it to help a friend set up a Wordpress site. And now I don't hate it any more. It does the job it was designed to do in a reasonably non-horrible way. I don't think I'd ever try to build a Facebook-scale app with it ;-), but as the BASIC of web site creation, it doesn't completely suck.
- buboard 6y agofacebook was built and grew in php tho
- dreamcompiler 6y agoDid you notice my ;-) ?
- kensai 6y agoAnd then decided to ditch it for its own version: Hack!
- deleted 6y ago[deleted]
- thkim 6y agoNothing "wrong" with PHP itself, but it's clearly not designed for modern web programming patterns which makes it feel outdated. No separation of model-view-controller, not friendly for API or AJAX, no class structure until later add-on, and so on.
- eithed 6y agoPlease use a framework - Laravel / Symfony has all of these
- malinens 6y agoit's the most friendly kanguage for ajax. Nothing beats json_encode in simplicity
- cutler 6y agoThat's because PHP, like Ruby, Python and Javascript, is not an MVC framework. If you want that you have Laravel and Symfony. PHP, Laravel and Symfony are perfectly fine for returning JSON instead of HTML. I don't get your point. As for classes PHP has had them for 16 years.
- kapv89 6y agoThe "annotation syntax" is becoming a language feature with PHP8 attributes.
- coldtea 6y ago>My only real gripe with PHP is the annotation syntax. Yikes. Stuff that's in comments SHOULD NOT AFFECT RUNNING CODE. Who came up with that? Don't check out Golang then...
- cutler 6y agoCould you elaborate?
- coldtea 6y agoThey use comments for compilation directives, build instructions, code generation and other such stuff. https://dave.cheney.net/2018/01/08/gos-hidden-pragmas https://dave.cheney.net/2018/01/08/gos-hidden-pragmas https://dave.cheney.net/tag/build-constraints https://dave.cheney.net/tag/build-constraints https://blog.carlmjohnson.net/post/2016-11-27-how-to-use-go-generate/ https://blog.carlmjohnson.net/post/2016-11-27-how-to-use-go-...
- balfirevic 6y ago> Is it a perfect language? No. But which language is? This has got to be one of the worst arguments (or rather, pieces of rhetoric) there is [0]. [0] - https://www.lesswrong.com/posts/dLJv2CoRCgeC2mPgj/the-fallacy-of-gray https://www.lesswrong.com/posts/dLJv2CoRCgeC2mPgj/the-fallac...
- elric 6y agoSomething about perfect being the enemy of good comes to mind..
- tomaszs 6y agoI agree with you. PHP did its job. For years it provided features no one had. Actually i find it funny people who didn't code in PHP criticize it. Or, even better, if JavaScript, Node.js, ASP.NET or TypeScript brag about how PHP is bad.
- gnud 6y agoI also wrote a lot of code in PHP back in the day - although less than you, it sounds like. I started using PHP just before PHP 5 came around. And let me tell you - working with legacy code that used magic quotes or auto-globals is the reason I'm a die-hard strong type programmer today. On the other hand, PHP didn't get in the way. It gave you a simple way to map a URL to a piece of code, and then let you respond to the request however you wanted - without "middleware" and "routers" - or "servlets". I sometimes miss that.
- elric 6y agoGood grief. Magic quotes was such a terrible to work around a terrible problem. Let's try to fox SQL injection by magically messing with user input in the assumption that it will end up being appended to an SQL query Yikes. You'll be pleased to know the feature no longer exists. I haven't mourned its loss. Disabling that was a mainstay of any PHP config I touched.
- schoolornot 6y agoPHP also has great bindings for openssl versus the incomplete pyOpenSSL library in Python.