Basic class definitions begin with the
keyword class, followed by a class name,
followed by a pair of curly braces which enclose the definitions
of the properties and methods belonging to the class.
The class name can be any valid label which is a not a
PHP
reserved word.
A valid class
name starts with a letter or underscore, followed by any number of
letters, numbers, or underscores. As a regular expression, it
would be expressed thus:
[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.
A class may contain its
own constants, variables
(called "properties"), and functions (called "methods").
the simple example of php class is following.
<?phpclass _DemoCLass{
// property declaration
public $Member1 = 'Value of Member1';
// method declaration
public function DisplayValue()
{
echo $this->var;
}
}?>
Note:-
The variable name and class name are case sensitive so when you make object of class that time use in proper way else it's give an error.
The pseudo-variable $this is available when a
method is called from within an object
context. $this is a reference to the calling
object (usually the object to which the method belongs, but
possibly another object, if the method is called
statically from the context
of a secondary object).
Make object of class.
//it's create a new object of
_DemoCLass class
$NewObj = new
_DemoCLass;
//call method or function of class
$NewObj ->
DisplayValue();
No comments:
Post a Comment