7. What does a readonly property guarantee in PHP 8.1+?
- It can be initialised once and not modified afterwards
- It can never be read
- It is static
- It is automatically serialised
जवाब देखें
जवाब: It can be initialised once and not modified afterwards
Readonly properties are write-once, making immutable objects straightforward.
पाठ: Classes, Constructor Promotion, Readonly and Enums
8. What does the #[\Override] attribute (PHP 8.3) do?
- It makes a method final
- It hides the parent method
- It enables traits
- It causes an error if the method does not actually override a parent or interface method
जवाब देखें
जवाब: It causes an error if the method does not actually override a parent or interface method
#[\Override] turns accidental non-overrides, such as typos, into errors.
पाठ: Inheritance, Interfaces, Abstract Classes and Traits
9. What does `public private(set) string $status` mean in PHP 8.4?
- The property is private for reading and writing
- The property is constant
- Anyone can read the property, but only the class itself can modify it
- It is a syntax error
जवाब देखें
जवाब: Anyone can read the property, but only the class itself can modify it
Asymmetric visibility separates read access from write access.
पाठ: Property Hooks, Asymmetric Visibility, Attributes and Magic Methods