Programming Languages PHP Objective
Sep 23, 2025

Which PHP 8+ feature allows you to create anonymous classes with constructor property promotion?

Choose the correct answer:
A) Anonymous classes cannot use constructor promotion
B) new class(public $prop) {}
C) new class { public function __construct(public $prop) {} }
D) class(public $prop) {}
Detailed Explanation

Explanation: Anonymous classes in PHP 8+ can use constructor property promotion just like regular classes. The syntax is: new class { public function __construct(public $prop) {} }

Discussion (0)

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

Share Your Thoughts
Feedback