Hacker News new | ask | show | jobs
by atarian 459 days ago
I was hoping for an actual desktop app powered by PHP, which would be really cool having PHP as a desktop runtime.
4 comments

You might enjoy https://nativephp.com/
Lol, what? Haven't heard of this... What's your experience with nativePHP?

While i am a defender of modern (!) php for web applications, this does sound rather weird. But also interesting. Thanks for the link.

I wonder though how "native" this is? Glancing over the docs it seems to be built upon tauri / electron? Not as native as i expected, but probably more native than most people would dare to think about...

I haven't used it for anything, but it is developed by some friends of mine. It's certainly a novel approach! And they got it working on iOS too
Lol indeed... I also still love PHP. For most small apps that's my go to backend, because who needs to worry about keeping Node running on some server you forgot about 2 years ago? And it's a fully modern language.

I'm delighted that there's some kind of desktop API here. On the one hand, the fact that it's talking with an Electron shell seems sort of magical. But it begs questions like, why wouldn't I just use a fully JS stack? And... since I've never created a graphical app in PHP before, would this be the right time to start?

I'd also say ...patterns like this that return the object you modified in PHP weird me out, even though they're common in JS going back to JQuery:

>> Dialog::new() ->title('Select a file') ->open();

It's an interesting "modern"-ish design choice, but it doesn't feel very PHP-ish. $dialog = new Dialog('title') followed by $dialog->open() would feel more sane.

That heavily depends on the framework you use. Laravel uses call chains a lot, and with PHP 8.4 (or even 8.3?) you can chain on new:

  new Dialog()->title('Select a file')->open();
Just from a high level, chains on 'new' are actually kind of awful. They're bad in a world like JS where lots of classes need to call async functions to spin up, but they're desperately worse in PHP where you really have to consider everything to be a blocking call. Something basic like this could easily hang a whole thread if, e.g. the title chose to read from a remote file. And it would be quite hard to tell what was hanging it. This is when it feels like PHP is getting out over its skis. I understand the desire to keep up with the Joneses, but there's no real penalty to writing your example in three lines rather than one. It's not really functional either way, and it's not especially debuggable either.
How would it make a difference if you split the statements up? A bad API is a bad API, and I’m pretty sure you can design one in any language (e.g. hide a while (true) within an innocuous method). The way to trace it down is the same in PHP as elsewhere, too—use a debugger. All that said, just don’t design shitty APIs and give your methods useful names.

An advantage of being able to chain calls are fluent expressions that you can return immediately, for example from arrow functions or match expressions, which definitely makes for easier to read code.

Sibling mentioned nativephp, but PHP-GTK[0] was also a thing in the past!

[0]: https://gtk.php.net

I am aware modern PHP is actually pretty good, but having grown up with PHP in the 2000s I can't help but get chills up my spine every time I read '$nonWebThing written in PHP'
I've seen massive cli apps and services written in PHP, it's actually pretty good for that sort of thing and given no build or compile step the devex is quite nice.

There's trade offs of course but for things where disk or network is the bottleneck it performs just fine.

And Delphi for PHP.
Alas
...would it?

I guess maybe if it was PHP8 only...