Live data from Hacker News

PHP's Oddities

flowtwo.io

121–130 of 186 posts

Re: PHP's Oddities

#121
post #9

After over two decades of working in PHP, I'm now working in Java. PHP is basically Java-lite. I am absolutely loving the compile-time safety of Java, but I dearly miss PHP's maps and arrays. In Java, the amount of verbosity for defining a map/list and operating on it is overwhelming. Modern PHP is great. Many powerful language features, excellent performance, great community and package ecosystem, and decent enough…

If I remember it correctly, the "Java-lite" part comes rather late. PHP was more close to Perl and/or other old-days scripting language, it allows you to quickly launch a web page. Just

    

and you get a hello page with a parameter specifiable via `?user=` query.

But then people started to actually use it to build big sites, `echo($_GET['user'])` alone is not enough, it has to be:

    
So people started to add module/components as well as ways to load and use those components, to enable them to write code like:

   is_valid(new Integer(0, 100), $source, $name);
   } // Or something like that, hasn't write a single line since PHP5.
That's when it got it's Java look.

Re: PHP's Oddities

#122
post #109
post #9

After over two decades of working in PHP, I'm now working in Java. PHP is basically Java-lite. I am absolutely loving the compile-time safety of Java, but I dearly miss PHP's maps and arrays. In Java, the amount of verbosity for defining a map/list and operating on it is overwhelming. Modern PHP is great. Many powerful language features, excellent performance, great community and package ecosystem, and decent enough…

Maps should be a first class type in every language. I have this thing I want to do in C. Now my C is very weak so my plan was to do a prototype in python, keeping in mind the C ecosystem then sit down with my old copy of "The C Programming Language" and struggle through it. Doing it with no dicts was rough. I am normally the sort to avoid adding any libraries I don't have to but if anyone has any hints to simple has…

you may try https://github.com/nothings/stb/blob/master/stb_ds.h. a single header implementation for both dynamic array and string based hash table

Re: PHP's Oddities

#123
post #121
post #9

After over two decades of working in PHP, I'm now working in Java. PHP is basically Java-lite. I am absolutely loving the compile-time safety of Java, but I dearly miss PHP's maps and arrays. In Java, the amount of verbosity for defining a map/list and operating on it is overwhelming. Modern PHP is great. Many powerful language features, excellent performance, great community and package ecosystem, and decent enough…

If I remember it correctly, the "Java-lite" part comes rather late. PHP was more close to Perl and/or other old-days scripting language, it allows you to quickly launch a web page. Just and you get a hello page with a parameter specifiable via `?user=` query. But then people started to actually use it to build big sites, `echo($_GET['user'])` alone is not enough, it has to be: So people started to add module/componen…

Namespaces were added long after that step.

Re: PHP's Oddities

#125
post #120

Earlier quoted context omitted.

XHP was a modified PHP before Hack came about, but only Hack supports it now. XHP did have a longer reach though: JSX is its direct descendant.

Making it an extension rather than default was a mistake on PHP's part. 99% of PHP is being run on shared servers and most people cant recompile it, and most of the rest just won't. Having a language whose entire purpose is to be a templating language for HTML have no concept of what HTML is, is just ridiculous. You have to use a templating framework that rolls its own ad-hoc DSL and parser to manage context just to…

It was never any kind of official extension, it was an outright fork of PHP (it changed the grammar) and FB never really attempted to push it to core, or really engage with PHP's core dev process in any way. PHP came about in the era of server-side includes, and expecting it to have grokked the DOM structure out of the box is just hindsight.

Anyway, I don't even think about server-side rendering anymore, and for the last few days have had Claude "shitting out" Vue components that replace legacy Bootstrap 3 components with html5 alternatives for my PHP app to use via Inertia.js. The axe-grinding is not helpful to either of us.

Re: PHP's Oddities

#126
post #102

Earlier quoted context omitted.

Isn't exactly their complaint? It's called an array, referred to consistently everywhere as an array, but it just ... isn't.

Apparently array is short for associated array:-)

In PHP the array index supports different key types and there's various optimizations that need to happen when the indexes are all numeric, mixed, or all strings or anything else. Technically it's called associative as soon as even one of the indexes isn't numeric. Internally though they are always numeric and anything non integer is hashed internally with DJB2 (Daniel J. Bernstein) hash algorithm and then stored. Using a non numeric index is slightly slower for that reason.

Re: PHP's Oddities

#127
post #79

Earlier quoted context omitted.

Did someone reply to him with this meme? https://knowyourmeme.com/memes/we-should-improve-society-som...

No, in 2006 it was still considered poor form to reply with a low-effort meme phrase instead of meaningfully criticizing his position with your own.

Depends entirely on the forum.

I remember it being somewhat common for people to make forum posts consisting entirely of a joke image. However, they weren’t called memes at the time as the word had yet to be popularized.

Re: PHP's Oddities

#128
post #120

Earlier quoted context omitted.

Making it an extension rather than default was a mistake on PHP's part. 99% of PHP is being run on shared servers and most people cant recompile it, and most of the rest just won't. Having a language whose entire purpose is to be a templating language for HTML have no concept of what HTML is, is just ridiculous. You have to use a templating framework that rolls its own ad-hoc DSL and parser to manage context just to…

It was never any kind of official extension, it was an outright fork of PHP (it changed the grammar) and FB never really attempted to push it to core, or really engage with PHP's core dev process in any way. PHP came about in the era of server-side includes, and expecting it to have grokked the DOM structure out of the box is just hindsight. Anyway, I don't even think about server-side rendering anymore, and for the…

Lol to true. Who even uses twig or smarty anymore hesitantly raises hand

Re: PHP's Oddities

#129
post #85

Earlier quoted context omitted.

yes I say this now very often, that PHP has morphed into runtime Java. Quite nice in some ways. In PHP though the STDlib is not very well thought out, it may be fun(needle,haystack) or fun(haystack,needle) and you just have to remember empty() will do weird stuff like a string with the value "0" is also empty, so not great for parsing things. A lot of footguns and the best way to avoid that is with a decent linter th…

Why not just use a proper code editor with inlay hints, inline documentation, and autocompletion instead? These things are a non-issue, unless you’re working with Notepad++ or something.

Yea VSCode or Eclipse does this.

Re: PHP's Oddities

#130

I hadn't done any PHP in almost 20 years, not since my studies when LAMP was still the way to go. But recently I had a reason to create a dynamic web page (not what I usually do) and went with PHP. Haven't regretted it. I haven't run into any of the quirks. I keep things simple, and it just works. The only problem I ran into was the realization that PHP is the wrong tool for long running tasks. After some rogue reque…

Try https://reactphp.org/ for job running. Use apc or memcached for persistent storage. Don't run jobs through web. Queuing things (you can start with a basic rdbma for your queue storage) and have a job runner fire them from a job runner. Can all be done in PHP. Have scaled it to billions per 24 hours.
Post reply on HN