php Object | How to declare and use Object variables for PHP classes

PHP Objects

Once a class is created or defined, you can use it as many times as you need by using object variables as follows:

Syntax

$obj = new classname;

$Objcar = new carnewModel;

So you have to give name to your object variable by $variable_name. On right side of assignment operator you have to use new keyword followed by class name.

Example of CarnewModel class


Creating Object

$obj_car = new carnewModel;

An object containing carnewModel class is created.

Also see PHP Class

Was this article helpful?

Related Articles

Leave A Comment?