PHP Classes
- Class is a user defined data type in PHP.
- In order to define a new class, PHP provides a keyword class, which is followed by a name.
- Any label that is valid as per PHP's naming convention (excluding PHP's reserved words) can be used as name of class.
CONCEPT OF CLASS IN PHP :
- Social class, also called class, a group of people within a society who possess the same socioeconomic status.
- Besides being important in social theory.
- The concept of class as a collection of individuals sharing similar economic circumstances has been widely used in censuses and in studies of social mobility.
TYPES OF CLASS IN PHP :
- Upper
- Middle
- Lower
- Peasants
- Under-class.
SYNTAX TO CLASS IN PHP :
<? php class person { } ?>
PHP OBJECTS
- Object is a compound data type (along with arrays).
- Values of more than one types can be stored together in a single variable.
- Object is an instance of either a built-in or user defined class.
- In addition to properties, class defines functionality associated with data.
- Primary variables, arrays and other objects can be cast to object data type using casting operator.
EXAMPLE :
<?php
class SayHello{
function hello(){
echo"Hello World";
}
}
$obj=new SayHello;
$obj->hello();
?>
OUTPUT :
Hello World