Like C++ and Java PHP also support object oriented programming.
Class are essentially user defined data types. Class are where we create a blueprint for the structure of methods and attributes. Individual objects are instantiated, or created from this blueprint.
Class is a programmer-defined data type, which includes local methods and local variables.
Class is a collection of objects. Object has properties and behavior.
Syntax -
Class is defined by using the keyword class followed by the name you want to give your new class.
<?php
class Person {
}
?>
Note -
We enclose a class using curly braces ( { } ) … just like you do with functions.
Example -
<?php
class Person {
public $name;
public $age;
// Method
function SetName ($name,$age) {
$this->name = $name;
$this->age = $age;
}
}
?>
No comments:
Post a Comment