Those can be initialised one time only, and only from the scope where it has been declared, otherwise the property will throw an error exception.Īlong with the new additions comes a small list of deprecations, which can be found in the PHP wiki. This alllows developers “to directly expose public readonly properties, without fear that class invariants could be broken through external modification”. The update also contains “first-class readonly properties”. PHP 8.1 allows their use in parameter default values, attribute arguments, static variable initializers and global constant initializers. The language now relaxes the restriction around new expressions inside initializer expressions. Options to declare strings or ints (=backed enums), extend classes, and implement interfaces are included and are hoped to help devs write more readable code. The syntax is thus quite similar to the one used for classes and interfaces. It is declared via the “enum” keyword which should be followed by its name. This is an enumerated type with a fixed number of possible values already available in languages like C and Python. The addition of enumerations is very significant. “It contains many new features, including enums, readonly properties, first-class callable syntax, fibers, intersection types, performance improvements and more.” “PHP 8.1 is a major update of the PHP language,” they claim. This week the PHP development group announced the release version 8.1 of the programming language. The new features include enums, Fibers, and readonly props.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |