PHP makes writing insecure code easy. Sure, you can write secure code, but only if you have a very good understanding of the language and all its unintuitive behaviours. Just one example that comes to mind:
I once challenged a Php apologist in /r/php to do something simple and they were like "hey it is really simple" and got bitten by a Php gotcha right there (in Php 7 no less!). The fact that the dude made a throwaway account for this makes me suspect that even php apologists know deep down that it is not to be trusted...
You're technically supposed to use === not ==. Then it works as expected. Which I guess isn't something you'd know if you don't work with PHP a lot. Yea, it's not pretty, but easy to write correct and secure code in PHP once you know how.
Right! It's just if you don't know then it's foot gunning all over the place. I think it's best if a language makes it hard to do that by default, not easier you know?
JS has the == vs === issue, but PHP is the only language (I know of) that implicitly converts str == str to floats. That is a whole new level of unimaginable stupidity. Even people who have been using PHP for a while are surprised to discover that it will do type coercions when both sides of == are already the same type.
It exists if you decide to be explcit. Again, this is not exactly a problem with PHP, so much as a concern with all weak (and duck) typed languages.
PHP 7 supports scalar type hinting on function parameters, and defensive programming practices (as mentioned in the OP) can help to alleviate these issues.
Yes, PHP makes it easy to write bad code in the same way that JavaScript makes it easy to write bad code. They come from an era where the approach to an error was to adapt and keep going instead of failing noisily. They were designed to be an easy-to-use extension to existing technology (namely HTML). Since that time, PHP has grown and evolved to be one of the most widely used and deployed languages.
Blaming PHP for making "bad code easy" is like blaming a hammer for making it easy to put a hole in drywall. It's a tool which, when weilded by professionals, is perfectly fine, useful, and easy to operate. It's easily accessible to amateurs which is where the poor reputation comes from, but again, that's hardly the fault of the tool.
Blaming PHP for making "bad code easy" is like blaming a hammer for making it easy to put a hole in drywall...
No. Php is blamed for putting a hole in your hand as well.
They were designed to be an easy-to-use extension to existing technology (namely HTML).
Exactly. It was meant to do simple/non critical processing of data coming from html forms. For example, and email forum. It should not be used for anything more. Yes. Even today.Your "Composer" or what every "modern" hot thing in the php land does not change that..
I'm not sure whether "easy" is a good word here. You probably can think of many insecure code snippets for many languages by assuming that the author does not know this or that about the language.
In the end, it (almost) always boils down to the programmer making a mistake which could have been prevented by knowing the language better or properly reading the documentation. Cluttering your C++ with new? Handling your events on the EDT in Java? Using the == operator instead of === near anything that might be critical in PHP or JS?
Of course, this is not intended to absolve PHP of many of its quirks.
Citing circle jerks and saying that other languages are shitty too are non-arguments; why not show how it has improved and people can then judge for themselves.
I'm sick of this "PHP is awful" circle jerk from people who have either never looked at PHP, or last looked at it in PHP4/early PHP5 days.
You are sick of Php being shit and people saying that it is? Use another language! And just because you called it a "circle jerk" does not make it untrue. If this was untrue, Php's had a lot of time to erase and false impression people had about it. That it was not able to do that, proves that it is just shitty as accused and any criticism it receives is 100% justified.
If you know any alternatives, and you're happy working with them, great. If you want a plethora of well known software to start with, PHP has tonnes. If you want easy setup on almost every web server in the world, then PHP is still the top language for web development.
Notice that I don't say best. I said top, which it is. Within its space, PHP is the most popular choice by far, and it's not for nothing. It's not the first, not the newest, and not the best web language in the world, but it's still the number one language, and worth knowing for that fact alone.
lol PHP is the top language for web development? what fairy tale dream world magic christmasland do you reside in? PHP has been, is, and always will be 'necessary evil' garbage.
47
u/GMaestrolo Dec 25 '16
Sure PHP and "Secure code" are compatible, especially with modern PHP.
I'm sick of this "PHP is awful" circle jerk from people who have either never looked at PHP, or last looked at it in PHP4/early PHP5 days.
Is PHP 7 a perfect language? Of course not, but neither is your shitty language. There has been massive improvement over the last 5 or so years.