Programming Languages PHP Objective
Sep 23, 2025

What is the correct way to implement a PHP 8+ constructor property promotion?

Choose the correct answer:
A) public function __construct(public $name) {}
B) public function __construct($name public) {}
C) public function __construct(var $name) {}
D) public function __construct(property $name) {}
Detailed Explanation

Explanation: PHP 8.0 introduced constructor property promotion, allowing you to declare and initialize properties directly in the constructor parameters by adding visibility modifiers (public, private, protected).

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback