Announcement

Collapse
No announcement yet.

PHP 8.3 Released With Typed Class Constants & Override Attribute

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP 8.3 Released With Typed Class Constants & Override Attribute

    Phoronix: PHP 8.3 Released With Typed Class Constants & Override Attribute

    PHP 8.3 is out today as the latest major annual update to the PHP programming language...

    Phoronix, Linux Hardware Reviews, Linux hardware benchmarks, Linux server benchmarks, Linux benchmarking, Desktop Linux, Linux performance, Open Source graphics, Linux How To, Ubuntu benchmarks, Ubuntu hardware, Phoronix Test Suite

  • #2
    I predict that PHP will exhaust all available "reserved words" some time next year and have to move on to reserved sentences... this will of course continue to be generated using ChatGPT...

    Comment


    • #3
      Michael

      typo

      " attribute RFC ti check" I think that should be "to"


      Comment


      • #4
        Originally posted by zexelon View Post
        I predict that PHP will exhaust all available "reserved words" some time next year and have to move on to reserved sentences... this will of course continue to be generated using ChatGPT...
        PHP is not even top contender with the amount of keywords it uses (83). For example C++ (97) and C# (102) use more. COBOL (357) being on its own league.
        PHP in its language format is in similar level with Javascript and Python etc. PHP has gained 4 new keywords in the past 3-4 years. I would not worry about the "next year" so much.

        Where PHP mostly gets the extra load is because it also works as templating language making the language syntax duplicated (very unique at that). For example:

        Code:
        <?php
        print '<body><ul>';
        foreach ($foo as $bar) {
            print "<li>$bar</li>";
        }
        print '</ul></body>';
        ?>
        Code:
        <body>
        <ul>
            <?php foreach ($foo as $bar): ?>
                <li><?= $bar ?></li>
            <?php endforeach; ?>
        </ul>
        </body>‚Äč
        Both do the same thing, but latter is nicer format inside templates.

        Comment


        • #5
          There are relatively few backward-incompatible changes with this release, so it should only take WordPress a decade or so to fully support it.

          Comment


          • #6
            I just don't get the need for typed constants. Type can be inferred from the value. Is it because constants aren't constants in PHP? At least class constants can be overwritten ("shadowed") by the subclass, so you might need to make it strongly-typed so that at least the type matches if nothing else does...

            it's sad because it will eventually become a part of a new PSR style standard to make all constants typed, and then we have to start adding useless visual boilerplate to our code.
            Last edited by curfew; 24 November 2023, 01:54 AM.

            Comment


            • #7
              Originally posted by curfew View Post
              I just don't get the need for typed constants. Type can be inferred from the value. Is it because constants aren't constants in PHP? At least class constants can be overwritten ("shadowed") by the subclass, so you might need to make it strongly-typed so that at least the type matches if nothing else does...

              it's sad because it will eventually become a part of a new PSR style standard to make all constants typed, and then we have to start adding useless visual boilerplate to our code.
              You mean "on top of some of the useless boilerplate code that is already out there" in the form of external libraries that bring everything AND the kitchen sink when you import them? Yeah, yeah I know that bloated import behavior seems mainly limited to Android (any others?) developers, but who is to say that disease will not spread to other platforms?

              Seriously, programming has gotten so sloppy and so bloated since I learned BASIC, Pascal, C, and x86 Assembly some decades ago. Libraries that bring in WAY TOO MUCH when you import them. Sales & Marketing folks that "need" every blinky gee-wiz look to their product promotions. Webmasters forced to support only the latest, newest web browsers rather than trying to keep their sites as inclusive as possible. Where will this nightmare train end?

              Comment


              • #8
                Even though I rarely code in PHP these days, I do keep an eye on it and have to say it has evolved very nicely over the years and I do think it is a good language (for web development).

                However, some things I miss from PHP is ability to generate UUID (it's not available in PHP standard library so you have to use a a third-party Composer package).
                Ability to declare the type of array properties. Yeah, an array can contain anything since PHP doesn't support generics, but it would nice if PHP either supported generics or just had some unenforced type hint.
                Ability to deserialize JSON into a class. Imagine if PHP had support for generics and you could do
                PHP Code:
                var $employee json_decode<Employee>($json); 

                Comment


                • #9
                  Originally posted by curfew View Post
                  At least class constants can be overwritten ("shadowed") by the subclass, so you might need to make it strongly-typed so that at least the type matches if nothing else does...
                  This is exactly the reason. Check https://www.php.net/releases/8.3/en.php

                  Comment


                  • #10
                    Originally posted by iruoy View Post

                    This is exactly the reason. Check https://www.php.net/releases/8.3/en.php
                    I've been sick so my brain doesn't work very well today. This same trick has been used with other aspects of PHP since the scalar types were introduced. Only new code designed to run on PHP 8.3 can use typed consts and therefore can safely be subjected to stricter conformity checks without breaking backwards-compatibility. So I was wrong in my prior message.

                    It's just a stupid idea that "constants" can be changed at a whim, making them non-constant. It's called late static binding and was forced into PHP because lots of singleton-based frameworks had started discovering that their idiotic design pattern is, well, idiotic, but instead of blaming themselves they framed it as a shortcoming of the PHP language.
                    Last edited by curfew; 24 November 2023, 09:39 AM.

                    Comment

                    Working...
                    X