Skip to main content
InterviewHubPRO
Section Overview
Q4

Question 4 of 50

Part 1: Core Language, Execution Lifecycle & Types (1 - 10)

8%
PHP & Zend Engine (50 Qs)•Part 1: Core Language, Execution Lifecycle & Types (1 - 10)

What is Constructor Property Promotion in PHP 8+ and how does it reduce boilerplate?

junior LevelCode ExampleLifecycle

In Simple Words: Declares class visibility and types directly in the constructor arguments, automatically assigning them to class properties.

php
class OrderDTO {
    public function __construct(
        public readonly string $orderId,
        public readonly int $amount,
        public readonly ?string $notes = null
    ) {}
}