Advanced PHP
June 3, 2026 1 min read

PHP OOP __constructor method

HS
HEMANT SINGH
Technical Writer & Educator

In PHP constructor is a magic methods that is used to initialize the properties of the class.

class Product{
	public $name, $price;

	public function __construct($name, $price){
		$this->name = $name;
		$this->price = $price;
	}
	public function display(){
		echo "
		Name: $this->name <br/>
		Price: $this->price <hr/>
		";
	}
}

$item = new Product("Jeans", 4000);
$item->display();