3 ms·
> Keys are sometimes strings, sometimes ints. And you don't always know which it is! Could you give an example? Because I've never had any issues with it and f
by lillesvin 6y ago
> Keys are sometimes strings, sometimes ints. And you don't always know which it is!
Could you give an example? Because I've never had any issues with it and find it very predictable.
> The fact that you can't typehint everywhere also sucks.
Type-hinting is being implemented and is already available in most places. But why you'd expect that in a dynamically typed language is beyond me.
> No generics sucks.
Again, dynamic language.
> No threads sucks.
pthreads has been considered stable since early 2014: https://pecl.php.net/package/pthreads https://pecl.php.net/package/pthreads
> Globals suck
Are you talking about "register_globals" which had its default setting changed to "off" 18 years ago and was completely removed 8 years ago: https://www.php.net/manual/en/security.globals.php https://www.php.net/manual/en/security.globals.php ?
> But is that because PHP did anything useful, or because Apache and Nginx support PHP out of the box?
Do they? Last I checked you had to install and enable support for PHP just like anything else. Unless you're talking about bundles like MAMP, but then it doesn't really make much sense.
You may claim that you've used PHP in earnest, but I honestly find that a little hard to believe when seeing these claims. And I don't mean that I expect you to understand all the little edge-cases of type-coercion, but if you'd really needed threads I'm sure you'd have stumbled upon pthreads, and if you've been using globals, then you've been following some oooooold guides.
- ragnese 6y agoYour response is almost exactly the same as waheoo's. Please see my reply to his for everything you asked here.
- lillesvin 6y agoYeah, I noticed after I'd missed your reply there the first time around. Sorry. I'm still confused about the array keys though. I'm not sure I understand the example you gave in your other comment. And I'm also curious which Apache and Nginx has PHP installed and enabled by default.
- ragnese 6y agoThe array key thing doesn't crop up often, but I've had it happen. Sometimes you are parsing something, such as "all files in this directory" and want to use the filename as the key and maybe store metadata or something as the value. Well, the second one of those filenames looks like a number, you're basically screwed. Now your array has some string keys and some int keys and operating on it is inconsistent at best. And, you're right, of course that Apache and Nginx don't actually support PHP out of the box. It's been a bit since I've configured a server and I forgot that mod_php is an extra step. That is definitely the main "pro" to using PHP, though- the deployment is great and so easy I can literally forget it. ;)
- lillesvin 6y agoYeah, alright, I understand your example now but I would argue that it's more of a problem with actually using filenames as array keys than it is a problem with PHP. Even so, wouldn't you be able to ensure that it's a string by doing `$array[(string)$filename] = ...`? (Again, I don't think using filenames for array keys—in any language—is a good idea but we're theorycrafting here.)
- ragnese 6y ago> Yeah, alright, I understand your example now but I would argue that it's more of a problem with actually using filenames as array keys than it is a problem with PHP. No. Just no. There is no reason, a priori, that you can reason that filenames shouldn't be keys in a hashmap. I think you're just projecting from "can't be done reliably in PHP" to "software should not do it" which are NOT the same things. Seriously. What is it about filenames that causes you to think "No. There's never a good reason to map a filename to data without defining a whole new type"? What other things scream out to you that should never get to be keys for dictionaries? Names? Planets? Flavors of candy? Would you really believe this if you were working in another language? It's exactly this reasoning that drives me nuts about PHP. You can point out the most insane behavior and someone always comes by and says "Nothing to see here. Just don't do that." Or "I just know not to do that, therefore PHP is fine." > Even so, wouldn't you be able to ensure that it's a string by doing `$array[(string)$filename] = ...`? (Again, I don't think using filenames for array keys—in any language—is a good idea but we're theorycrafting here.) Nope. Doesn't fix it. Because it's only converted to an int after being passed in. $filename was already a string. You're casting a string to a string and PHP, in all its wisdom, is then making it an int. And I think it speaks to my point that you tried and failed to solve the issue. That's not an affront to you, by the way. It's more evidence that PHP is impossible to do correctly.