Codeasearch.com - Search your code with us Login | Register | Contact us
  Forums > Php > Classes And Objects
musammil
Posted on Jan 17, 2008
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.

 Hot Discussion
Go Tech launches Android tablet for Rs 3,999...
Sony targets retailers with quick sales pitches and rew...
Share and discover new activities with Google Schemer...
Samsung gets 9 mn preorders for Galaxy S3: Report...
Google revamps search engine to think like a person...
 
 Discussion Topics
IT News
Php
Javascript
Technology Updates
Asp.Net
MySql
Ajax
Html
Fedora
Software Testing
Asp
Java
General
Flash
Ruby on Rails