Join Date: January 2008
Location: India ( Chennai )
Posts: 1
Classes And Objects
Hi I am very much interested to registering in this site.i am new bie to classes and objects.so i need clarification and help.with the Simple Program.
Thank You
S.Musammil
forums_reader
Posted on Jan 19, 2008
Join Date: July 2007
Location: India ( Chennai )
Posts: 24
Re : Classes And Objects
Hi, A class is a collection of variables and functions working with these variables. Variables are defined by var and functions by function.
Basic level of class and object ----------------------------------------------------------------------------- Create the file name as myClass.php
<?php class myCls { var $myDisplay;
function display() { echo $myDisplay ='Welcome to Class and Objects.'; } } ?>
Create another file name as sampleCls.php ---------------------------------------------------------------------------- <?php require_once("myClass.php"); ?> <? $objMyClass = new myCls(); ?> <html> <head> <title>Sample Classes and Objects</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? $objMyClass->display(); ?> </body> </html>
The above myClass.php which will have function in myCls class. Then after we are going to include the myClass.php into sampleCls then we will create object call $objMyClass then we will call the function display to print in the web page. This is the sample Classess and object.