PHP 8.4 Released With Property Hooks, Lazy Objects & Other New Features

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • blackshard
    Senior Member
    • Oct 2009
    • 599

    #11
    Originally posted by uid313 View Post
    A very good update with lots of new great improvements.

    ...

    uests/httpx library in Python.[/LIST]
    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

    • uid313
      Senior Member
      • Dec 2011
      • 6909

      #12
      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.
      Yes, I do because I code in lots of different languages which gives me insight and expectations. I like Python and PHP, but both of those languages suffer from weak JSON support and weak HTTP requests support.

      Comment

      • Havin_it
        Junior Member
        • Mar 2015
        • 30

        #13
        Originally posted by uid313 View Post
        JSON 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.
        Just 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 )

        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

        • uid313
          Senior Member
          • Dec 2011
          • 6909

          #14
          Originally posted by Havin_it View Post
          Just 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 )
          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

          • uid313
            Senior Member
            • Dec 2011
            • 6909

            #15
            Originally posted by all3f0r1 View Post
            Genuinely 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?
            PHP has gotten a lot better!
            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

            • caligula
              Senior Member
              • Jan 2014
              • 3309

              #16
              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.
              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:

              Comment

              • Jonjolt
                Phoronix Member
                • Aug 2013
                • 76

                #17
                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/
                I'm using jlink in production, lol one of the best features is just renaming the executable instead of trying to track down which process is which.

                Comment

                • caligula
                  Senior Member
                  • Jan 2014
                  • 3309

                  #18
                  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.
                  You're probably aware that such deserialization can be a security risk? Java serialization libraries provide fine-grained control over what can be deserialized.

                  Comment

                  • Havin_it
                    Junior Member
                    • Mar 2015
                    • 30

                    #19
                    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.
                    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

                    • uid313
                      Senior Member
                      • Dec 2011
                      • 6909

                      #20
                      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.
                      No, I don't think so, not JSON deserialization. Sure with marshaling (such as Pickle in Python) where you do some binary deserialization which deserializes methods and everything but not JSON which have no methods, only properties which can be number, string, array, object and boolean. Maybe if you deserialize properties with __ double underscores in their name as that is dunder in Python and magic methods in PHP but a JSON deserializer should take to properly deserialize a string.

                      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.
                      Yes, exactly, I would have an RESTful endpoint so I know how to deserialize based on the name of the endpoint which is in the URI, so for example I would have the HTTP endpoint /api/pets/ which accepts GET and POST requests, and I would have /api/pets/{id} which accepts GET, PUT and DELETE requests so when a client does a POST request against the pet endpoint I know that I should attempt to deserialize the request body into a Pet object which would be an instance of the Pet class. If the deserialization would fail I would return the HTTP status code 400 Bad Request.

                      Comment

                      Working...
                      X