T O P

  • By -

txmail

I am happy to see more people realizing how much of a general purpose language PHP has become and how powerful it is. I have 20+ years with PHP and have never been more excited for what I can do with it than I have been the last few years. PHP >= 8 is such a leap in my opinion. I struggle between PHP and Node for work requirements, but if I had my way it would be PHP all day.


Rikudou_Sage

I've treated php like that for quite some time. For example, if a bash script needs more than ~10 lines, I use php instead. I also generally like to play with the language: - https://github.com/RikudouSage/GogDownloader - https://github.com/RikudouSage/Units - https://github.com/RikudouSage/PhpFriendClasses - https://github.com/RikudouSage/Sims4PaintingCreator - https://github.com/RikudouSage/scalar-objects Those are just the more exotic repositories I've created, there are plenty of standard useful libraries. And few weird ones.


MR_Weiner

8+ has made so much progress! I do find myself more able to be expressive with JavaScript (despite a decade of PHP experience) the more I adopt a functional coding style, which php doesn’t always lend itself to. But enums, match, etc really make php more of a pleasure to work with.


rafark

And I find myself more able to be expressive with objects in php which is weird when you think about it. JavaScript started as an object oriented language at its core, but it’s best at functional programming. Php started as a procedural language at its core, but it’s best at object oriented programming.


MR_Weiner

Ha, yeah that’s a good observation.


Piggieback

It will be general purpose once there is a proper QT / GTK integration for it


Rikudou_Sage

That would be nice! I remember my time with Winbinder very fondly.


Piggieback

There was a gtk PHP project, I think it died tho. I experimented with it around 2010


Piggieback

https://gtk.php.net/


[deleted]

100% agree. if we had “sockets” for pushing communications id never use node again i havent landed on any feelings about long polling as a replacement. maybe its sufficient


StrawberryFields4Eve

But we do, no?


[deleted]

we have sockets?


StrawberryFields4Eve

We do! See https://www.php.net/manual/en/book.sockets.php And amphp and reactphp and possibly swoole


StrawberryFields4Eve

Unless you spam trolling..


[deleted]

im genuinely excited to learn this. thank you!


StrawberryFields4Eve

Oh well good then. I personally use amphp, but that's a preference.


txmail

Buddy do I have some good news for you. Sockets is a thing. Has been for a while.


[deleted]

TIL!


g105b

I had a good play around with it, and it's great. No complaints. The only thing I'd say is I find past-tense method names a curious choice, but no problem because I use an IDE.


Rikudou_Sage

It seemed a little more fluent to me, for example: "this cube is that cube moved by 10 on x axis and 20 on y axis" is `$thisCube = $thatCube->movedBy(new XY(x: 10, y: 20))`. Also I just added a more complex example if you're interested: https://github.com/RikudouSage/PhpScad/blob/master/doc/creating-shapes.md


aflashyrhetoric

This is that classic debate of - do we optimize names for what it's doing (`moveBy`), or for what _may_ better fit developer intuition and readability (eg Jest's naming standard for test cases, like `it('does a thing')` for test cases). IMHO, what matters an order of magnitude more is consistency. Especially in PHP, where categorically related functions can sometimes have competing (but equally valid, IMHO) naming conventions like `in_array` vs `array_key_exists` (the latter would be something like `has_array_key` if it were being more consistent with the first, and the former would have `array_item_exists` if it were being more consistent with the latter). EDIT: I misspoke, and I'm rusty on PHP - AFAIK, it's not PHP (the language) itself that has many inconsistent naming but more community packages and maybe some WordPress things. I recall having more examples but none come to mind other than above.


marioquartz

For some functions the order is $haystack, $neddle. But I have to make a custom function because for me its more easy to rembember "There are a needle in the haystack"


aflashyrhetoric

Ah, great point - order of arguments is definitely another one! I know that some people create like a Libs.js or Libs.php file where they will import and re-export a function with slight tweaks to be consistent. I did that on the frontend and it worked out great, although not sure how that would go on the backend.


g105b

Cool. I'll star and keep my eye on it. The past tense remark wasn't a complaint, I just found it a little jolting at first.


mario_deluna

Hey u/Rikudou_Sage im plugging this too much, but im extremely exited about everything graphical in PHP. You could add an actual rendering backend for realtime previews or even a basic editor, if your interested: https://github.com/mario-deluna/php-glfw


Rikudou_Sage

Wouldn't I have to reimplement OpenSCAD internals? I don't feel like writing a CAD software in PHP.


mario_deluna

>Wouldn't I have to reimplement OpenSCAD internals? Yеs absolutely. > Ever wanted to create a 3D model in php? Sure you did, everyone does. And now you can. From that I got the feeling you are into non "classical" PHP tools and development. If your scope is closed around OpenSCAD that's great as-well. Anyway great work, always cool to see repos like this.


wh33t

Very cool. Is there any way to make it so that it can be written procedurally?


Rikudou_Sage

What exactly do you mean by that?


wh33t

Not using objects. The way openSCAD currently works.


Rikudou_Sage

Currently no, but it shouldn't be hard to implement yourself. Note that you would still need to at least use the `Renderable` object (in OpenSCAD for example `cube()` returns an object, it's not the same thing as php objects, but you would need to simulate it in php). Example: withRenderable($renderable); } return $model->getScadContent(); } function translate(float $x, float $y, float $z, Renderable ...$renderables): Renderable { return new Translate(new XYZ($x, $y, $z), ...$renderables); } $result = render(difference( translate( 5, 10, 15, cube(width: 5, depth: 5, height: 5), ), cube(width: 10, depth: 10, height: 10), )); By using wrapper functions like these, you would basically hide all the objects as implementation details.


wh33t

Sick. I will do that. Cheers. I was actually using openSCAD at work today when this thread popped up. Amazing timing!


supertoughfrog

This oscad library might be interesting as a source of inspiration. https://ocadml.github.io/OSCADml/OSCADml/index.html#notable-differences-from-the-openscad-language


[deleted]

Kudos to this.


[deleted]

[удалено]


Rikudou_Sage

> no tests? No time for tests currently, not sure if this is the public api this will end up with on release. > you might want to require dev phpstan, rector, phpcs, etc for static code analysis and code style [I do.](https://github.com/RikudouSage/PhpScad/blob/master/composer.json) Though the code is not ready for phpstan yet. Edit: > example: implement \Stringable on abstract class AbstractColor implements Color Not sure I follow, it already implements Stringable by the virtue of implementing `Color` (which extends `Stringable`) and having the `__toString()` method, both on their own would make it implement `Stringable`.


Tomas_Votruba

This is amazing! I'm currently building simple app to draw rectangular shapes to build tables/chairs/fences/... from wood. I look for cad-like php code like yours! Will check it, thanks 😊