Originally posted by uid313
View Post
PHP 8.4 Released With Property Hooks, Lazy Objects & Other New Features
Collapse
X
-
Originally posted by blackshard View Post
You lament the very same things for python on every python news. Those are not serious issues for python and neither are for PHP.
Comment
-
-
Originally posted by uid313 View PostJSON support is very poor, you can only serialize to stdClass or an associated array, not to your own classes so you don't have type safety, and you cant override property names if you want to serialize a kebab-case JSON into a camelCase property.
There is the JsonSerializable interface but that is you doing the work of defining the serialisation format, not PHP, and I think that's how PHP wants it. If they prescribe a pair of functions to map defined class objects into JSON and back into the same classes, they in effect define an in-house JSON dialect and I can see why they would rather leave that up to you. Implementing JsonSerializable for your specific needs is pretty trivial and gives you full implementation control (like your property name translation example), and you can be lazy/efficient and put the impl in a trait or abstract ancestor class.
I would like to see an extension to json_decode() allowing to pass in a callable to fingerprint the decoded stdClass or array objects for however you encoded their classname, and return such objects (either by dumbly setting the properties or by you implementing an additional JsonUnserializable interface). The responsibility over the serialisation "format" would still be on you, but you wouldn't have to wrap json_decode() in your own function to iterate the output and identify the classes, and having that part done natively would likely perform far better.
Comment
-
-
Originally posted by Havin_it View PostJust to be nosy, can I ask what need you have of a class that you serialise from PHP and back into PHP, that it must be JSON? Why not just use serialize()? (Forgive my probable ignorance I am very sheltered )
Comment
-
-
Originally posted by all3f0r1 View PostGenuinely curious, I have a bad memory of how it felt to develop in PHP 5, years ago. Is it any better now? I know perfs have been a major focus, but apart from that, does it still feel like an opinionated "lego" language with no active enforcement of things like MVC?
Nowadays it is much more strict and you can use stronger typing to ensure that the quality is good, and lots of errors are now exceptions, etc.
PHP is still just a set of functions and classes that you use however you like, so yeah it gives you the building blocks and doesn't enforce any paradigm or design patterns like MVC. However if you want opinionated framework you can use the hugely popular Laravel framework.
Comment
-
-
Originally posted by Jonjolt View Post
The big thing I've noticed with PHP is the increase memory usage and external services for some of these projects, so much so I think the JVM would be a better option.
Here's a list of new features for Java 24:
Comment
-
-
Originally posted by caligula View Post
Funny thing is the next Java version will cut down even more bloat. Their jlink will leave out more unused code and the runtime representation of objects slims down a lot.
Here's a list of new features for Java 24:
https://openjdk.org/projects/jdk/24/
Comment
-
-
Originally posted by uid313 View Post
I want PHP to expose a RESTful Web API endpoint that serves JSON to be consumed by other clients and web applications like SPA JavaScript applications like React, Vue and Svelte.
Comment
-
-
Originally posted by uid313 View Post
I want PHP to expose a RESTful Web API endpoint that serves JSON to be consumed by other clients and web applications like SPA JavaScript applications like React, Vue and Svelte.
Comment
-
-
Originally posted by caligula View Post
You're probably aware that such deserialization can be a security risk? Java serialization libraries provide fine-grained control over what can be deserialized.
Originally posted by Havin_it View Post
OK but when objects are sent back to your PHP server, doesn't the URI structure tell your app what class of object it's dealing with already? (That is just how I see it being done normally.) Sorry if I'm being a PITA with the questions but I'm trying to grok what you'd like PHP to do, that other languages do better. Like, the Javascript end can't know implicitly the class from just the JSON either, unless both ends have a shared protocol to determine that based on the content's data or message metadata.
Comment
-
Comment