Class and Object in PHP
Advertisements
Class and Object in PHP
Class: This is a programmer-defined data type, which includes local functions as well as local data. You can think of a class as a template for making many instances of the same kind (or class) of object.
In PHP declare a class using the class keyword, followed by the name of the class and a set of curly braces ({}).
Syntax Create Class in PHP
<?php class MyClass { // Class properties and methods go here } ?>
Syntax
$obj = new MyClass;
In PHP, to see the contents of the class, use var_dump(). The var_dump() function is used to display structured information (type and value) about one or more variables.
Syntax
var_dump($obj);
Class and Object in PHP
<?php class MyClass { // Class properties and methods go here } $obj = new MyClass; var_dump($obj); ?>
Object: An individual instance of the data structure defined by a class. You define a class once and then make many objects that belong to it. Objects are also known as instance.
Syntax Class in PHP
<?php class phpClass { var $var1; var $var2 = "constant string"; function myfunc ($arg1, $arg2) { [..] } [..] } ?>
Syntax Create Object in PHP
<?php class MyClass { // Class properties and methods go here } $obj = new MyClass; var_dump($obj); ?>
Google Advertisment