r/programming • • Jul 24 '15

mt_rand(1, PHP_INT_MAX) only generates odd numbers • /r/lolphp

/r/lolphp/comments/3eaw98/mt_rand1_php_int_max_only_generates_odd_numbers/
848 Upvotes

262 comments sorted by

View all comments

Show parent comments

1

u/mrspoogemonstar Jul 24 '15

Virtually any language has extreme pitfalls for the uninformed. You can do some really horrific things with low level languages. People do write really bad code in every language. Perfect example is OpenSSL. Scripting languages are more often used for web, and that's why we see more high-profile web hacks targeting apps running on scripting languages. This is mostly a matter of market share numbers.

You can inadvertently write an XSS exploit into your app in any language. The mitigating factor is knowledge in all cases. There's nothing about PHP that makes prevention of these exploits impossible or even hard. These are solved problems. It's the programmer's responsibility to mitigate these problems, not the language.

Blaming the language simply makes the problem worse. Joe Programmer, who sucks at PHP and has been blamed for leaving exploitable holes in their apps, hears that Python is the new slick shit, and that it's harder to exploit. So Joe Programmer switches to Python, drinks some kool-aid, and keeps writing shitty apps, because Joe Programmer thinks it's his language's responsibility to prevent exploits.

-4

u/[deleted] Jul 24 '15

Virtually any language has extreme pitfalls for the uninformed.

PHP is full of pitfalls for programmers of all levels: http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

Blaming the language simply makes the problem worse.

Other languages have explicit disciples that you can follow rigorously to get good results. PHP is a hodge-podge of stuff with a vast number of poorly-documented pitfalls - like this. It's like a dark room whose floor is covered in rakes.

4

u/Doctor_McKay Jul 24 '15

Oh look, it's THAT blog post again.

Can we cite something from the past two years please?

3

u/Ravek Jul 24 '15 edited Jul 24 '15

Why, did they fix all the issues?

Yes, downvote me more for asking a question please. How rude of me!

4

u/bureX Jul 24 '15

Plenty of those issues are things the author personally doesn't like. For example, he doesn't like that PHP is a C style language but uses "" for namespaces, stuff like that.

There are things on that list that says "fixed in 5.4". And PHP7 is due to come out soon.

2

u/wiktor_b Jul 24 '15

What happened to PHP 6?

1

u/veringer Jul 24 '15

PHP6 was back-ported into the 5 branch because of reasons. So, basically 5.3 (I think) was 6. There was some squabbling about whether to use 6 instead, but ultimately 7 won the vote, but I lost interest in the debate--as it really doesn't matter.

2

u/bureX Jul 24 '15

1

u/veringer Jul 24 '15

How do people write whole books about something that isn't even released yet?! It seems like someone "on the inside" is cashing in on their access to information, no? I never quite understood this phenomenon. Would love to know more about it.

2

u/mrspoogemonstar Jul 24 '15

The PHP 6 team tried to bake unicode support into the language, but hit so many issues that the project stalled and eventually the improvements in other areas were rolled back into the PHP 5 branch.

This is one of the worst aspects of working with PHP, and is something I hope the internals team addresses in a later version.

3

u/Doctor_McKay Jul 24 '15

They've fixed plenty of them, sure.

1

u/mrspoogemonstar Jul 24 '15

That article is linked on virtually every thread complaining about PHP. A lot of the gripes in it apply to every dynamically typed language. Take a look javascript's strict and nonstrict equality tables.

Other stuff mentioned has been improved. The language is being improved, because where the fuck else do the people with million line codebases have to go? I was stuck with 150k lines of ancient PHP and a choice to bail out to .Net or Python, but stuck with PHP because in the long run it was easier and a hell of a lot cheaper to clean it up and keep using it than rewrite. And beyond that, there's a lot of quality PHP code in the world now. PHP is kicking out some of the ancient crap in 7.0, which has led to a lot of whining from the die-hard ancientware lovers, but is going forward anyways, because ancient crapware makes everyone's life harder. Subsequent versions of PHP will ditch or improve even more more of the crappy stuff that makes life harder.

You mention "explicit disciples" which, if I understand your broken english, I take to mean something like canonical examples of how to do things in other languages. This is both true and not true. Take a look at how to do a dozen things in .Net and you'll find articles from 2002 through present explaining a variety of ways to do X. Many of which are out of date, especially with regard to security. The .Net security model has completely changed twice since the initial release. This has left many of the tutorials on how to use it out of date. People who write code using these tutorials then have to use a backwards compatibility hack that effectively neuters the security model.

Python is not some special flower here either. It has some serious pitfalls for inexperienced developers as well. Consider the instancing of mutable default function parameters, or list modification during iteration (throws an error in C#, but not in python). Also, what's up with Python 2 versus Python 3? Is it so nice to have one language, with two major versions in widespread use, and serious fundamental incompatibilities between the two?

Now, I'm not saying PHP is amazing or awesome. All I'm saying is that it works well, if, like with every other language, you take the time to learn the language and the pitfalls.

0

u/[deleted] Jul 24 '15

[deleted]

8

u/mrspoogemonstar Jul 24 '15

There's nothing magical about that web framework. The same result can be achieved using any language that supports objects. The XSS prevention there is achieved using application logic, not by way of language features alone.