Live data from Hacker News

PHP 8.1.0

php.net

251–260 of 286 posts

Re: PHP 8.1.0

#251
post #197

Earlier quoted context omitted.

> When I write Javascript or Python, I have complaints and issues, but I enjoy writing code. I think PHP, for many programmers, including myself, is just a hostile and unenjoyable experience. Surely JS has at least an equal amount of foot-guns to PHP. I mean, at least PHP (to my knowledge) never had a meta-language written around it that compiles to PHP to make it safer.

Did Hack start that way, or am I misremembering?

IIRC Hack transpiles to C++ with an intermediate build step. So not exactly the same.

Re: PHP 8.1.0

#252
post #32

Earlier quoted context omitted.

Elegant is not the word I'd use to describe PHP. Solid, perhaps. Undoubtedly useful. But if there is elegant PHP, I haven't seen it.

Have you looked at any Laravel code? As someone who has worked from small startups to FAANG and inbetween, Javascript to PHP to Python to Go, I haven't found anything more elegant.

I have. Elegant it is not. Actually, it smells like Enterprise Java code, which made me flee from the Java ecosystem. To each his own, but this is not an elegant event listener (copied from the examples page):

  use App\Events\ArtistInformationFetched;
  use App\Services\MediaMetadataService;
  use Throwable;
  
  class DownloadArtistImage
  {
      private MediaMetadataService $mediaMetadataService; 
  
      public function __construct(MediaMetadataService $mediaMetadataService)
      {
          $this->mediaMetadataService = $mediaMetadataService;
      }
  
      public function handle(ArtistInformationFetched $event): void
      {
          $info = $event->getInformation();
          $artist = $event->getArtist();
  
          $image = array_get($info, 'image');
  
          if (!$artist->has_image && $image && ini_get('allow_url_fopen')) {
              try {
                  $this->mediaMetadataService->downloadArtistImage($artist, $image);
              } catch (Throwable $e) {
              }
          }
      }
  }
Source: https://laravelexamples.com/example/koel/events-listeners

Re: PHP 8.1.0

#253

Earlier quoted context omitted.

This example seems to be a great demo of why people do not like working with PHP. PHP makes the shit method the massively simpler way and the good method much harder. Now you open yourself up to risks like what happens if we accidentally let some user input change the file opened as well as the content written. While with rails, to do basically anything, you already have a full db ready and incrementing a counter usi…

>PHP makes the shit method the massively simpler way and the good method much harder. How it makes it harder? Or you compare PHP a language with Rails a framework? Maybe shut up if you have no idea or show us a pure Ruby code that does the same thing. Or install the most popular PHP framework, really learn that and then tell us that PHP made things harder. I don't know Ruby or rails so I can't shit on that like an id…

Please refrain from name calling and phrases like "shut up". They don't really add to the conversation.

Re: PHP 8.1.0

#254
post #18

Everyone laughing at PHP hasn't tried it for years, I'd bet. It started clumsy, true, but it became a solid and quite elegant way of doing things. And by things I don't mean just web development. The current limitations I see in PHP is that there is not an official multi-core coroutines solution.

I used Symfony and it was fine but there are some challenges: 1. The combination associative array/array data type is weird and I feel like the performance is not predictable unless you devote time to learning specifically about it 2. You're still stuck with all the weird legacy stuff, even if you don't use it, because someone else might bring it in 3. The OO stuff is basically like an old version of Java and a bit t…

> The OO stuff is basically like an old version of Java and a bit tedious to write. An IDE is definitely required

The OO 'stuff' in PHP is far better. Notably, Traits, Statics and Testing.

Java (and JUnit) do not work well with static methods/classes, when it's unironically the most effective way to limit state. In PHP you can create a static class, that has static utility methods. Now you can ensure you have no side effects - unless accessing static properties somewhere, ofc. Then PHPUnit has no trouble helping you test these. It's a huge improvement over the acrobatics of booting up Spring to manage a singleton (which isn't the same thing as a static class) whenever you want access to those real static methods.

Re: PHP 8.1.0

#255
post #52

Earlier quoted context omitted.

Wordpress has taken great strides to comply with the latest PHP standards so I'd say that's not quite fair to include it here.

I would say some contributors comply with standards - but the stuff coming from Automattic is scary. I ended up in a position where I've become responsible for a very high volume WooCommerce/Wordpress store and the things that I've seen in _brand new code_ is mind boggling. Their new, branded, in-house paypal plugin/integration is currently at 1.5/5 rating on the wordpress plugin marketplace [0]. It just doesn't work…

> Woocommerce doesn't rely on dedicated tables for orders or related metadata, it's all stuffed into 'posts' and 'post_meta'.

While I agree this is an antipattern it appeared to be the recommended way when I first got into WP plugin development. IIRC because one cannot guarantee hosting will backup all tables of the DB, and some DBs mix other non-WP stuff.

Re: PHP 8.1.0

#256
post #65

Earlier quoted context omitted.

More interested in what meaningful fixes can be done in some fraction of the 1.2s RTT of this rapid-fire style PHP development.

Output to html, meta refresh page every second. Pretty much real-time results.

> Pretty much real-time results.

This to me feels really underrated nowadays - at best, you shouldn't always have to reason about your code inside of your head and try to figure out how it'll work in detail, or read API docs for all of the obscure frameworks that you're using.

Test things in real time at first and in the cases where they don't, continue doing so, but with a debugger and stepping through everything bit by bit, or read the docs, or whatever the non-trivial cases will demand.

In my eyes, that's the exact same thing as autocomplete in IDEs - instant feedback, to free you from having to think about yet another mundane level of abstraction or API details, instead letting you solve the actual problems that you're faced with.

Re: PHP 8.1.0

#257

I've been using PHP since 5.x. Often had to work on older 4.x web apps. I find it interesting when I read people saying "PHP has come a long way. It's a proper language now, etc." If you work long enough with a language and figure out most its quirks, it's a breeze. It's nice that they are adding all these new features, but they are hardly what makes it or break it for me. Here is the one features that is taken for g…

> When debugging I can do that 50 times a minute. In interviewing, I've seen a few candidates re-run their application after making single statement changes. They'll rename a variable, re-run. Change a conditional, re-run. Introduce whitespace, re-run. These people aren't even confident in renaming variables! PHP enables this type of underestimation in your own abilities. You don't need to distrust yourself so much.…

> PHP enables this type of underestimation in your own abilities. You don't need to distrust yourself so much.

I've even had IDE refactoring tools fail on me whilst doing this, in type checked Java codebases, with reflection in place and annotations, which predictably caused problems down the road. At this point, i'll take any and every method that can help me in development, especially in the face of meaningless cruft and unreasonable complexity.

I'm actually writing this in my 5 minute break after being stuck at work 1 hour past my official work hours, due to some stupid bug where one service ignores a client certificate from service A, but not from service B on the server in containers.

The opposite end of this spectrum (my current circumstances) is completely unreasonable IMO - a change in code needs an app recompilation and a push to the container registry before it's deployed on the server (cannot reproduce locally, possibly proxy configuration is to blame, but it's so simple it should not be possible), whereas configuration changes need the Ansible playbook to run to the end, which also takes time.

Thus, my feedback loop is ~10 minutes for seeing a new way in which the app will fail to do something supposedly simple. Even in normal circumstances, local app reboots still take at least a minute or so, since JRebel and code hotswapping just doesn't work a lot of the time with the frameworks we're using. I'd take being able to see the changes in my code every X seconds over every X minutes any day of the week.

Even if i trust myself, i still want that freedom and speed of development and checking why everything breaks.

Re: PHP 8.1.0

#258

Earlier quoted context omitted.

To be clear, I’m not saying this is a good reason , but I’ve been doing it lately because otherwise the browser security features prevent a local auth service from passing tokens to the backend app via the browser. I need to figure out a way around this because the iteration loop sucks; probably I’ll add a flag to disable auth on the backend app so I can test non-auth-things locally.

Sometimes in that scenario my approach is to ssh into the app container and make the changes in there, moving the fix to version control when it is in a shipable state.

Yeah, that’s not a bad idea. I considered that but it seemed like a lot of work to set up the container to run an SSH daemon and work out the forwarding, but maybe I’m overestimating the work involved?

Re: PHP 8.1.0

#259

Earlier quoted context omitted.

I used Symfony and it was fine but there are some challenges: 1. The combination associative array/array data type is weird and I feel like the performance is not predictable unless you devote time to learning specifically about it 2. You're still stuck with all the weird legacy stuff, even if you don't use it, because someone else might bring it in 3. The OO stuff is basically like an old version of Java and a bit t…

> The OO stuff is basically like an old version of Java and a bit tedious to write. An IDE is definitely required The OO 'stuff' in PHP is far better. Notably, Traits, Statics and Testing. Java (and JUnit) do not work well with static methods/classes, when it's unironically the most effective way to limit state. In PHP you can create a static class, that has static utility methods. Now you can ensure you have no side…

I'm not sure what about Java is stopping you from making static classes.

Re: PHP 8.1.0

#260

Earlier quoted context omitted.

>PHP makes the shit method the massively simpler way and the good method much harder. How it makes it harder? Or you compare PHP a language with Rails a framework? Maybe shut up if you have no idea or show us a pure Ruby code that does the same thing. Or install the most popular PHP framework, really learn that and then tell us that PHP made things harder. I don't know Ruby or rails so I can't shit on that like an id…

Please refrain from name calling and phrases like "shut up". They don't really add to the conversation.

I apologize and I will try to do better.
Post reply on HN