Questions

OOPS Concepts in PHP


OOPS CONCEPTS IN PHP

Access control modifiers:
``````````````````````

Public:
used from anywhere in the script

Private:
only be used by the object it is part of; it cannot be accessed elsewhere

Protected:
used by the object it is part of, or descendants of that class

Final:
This variable or function cannot be overridden in inherited class es

Abstract:

This function or class cannot be used directly - you must inherit from them first



interfaces :



interfaces :
Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.

EXampleL:
<?php

// Declare the interface 'iTemplate'
interface iTemplate
{
public function setVariable($name, $var);
public function getHtml($template);
}

// Implement the interface
// This will work
class Template implements iTemplate
{
private $vars = array();

public function setVariable($name, $var)
{
$this->vars[$name] = $var;
}

public function getHtml($template)
{
foreach($this->vars as $name => $value) {
$template = str_replace('{' . $name . '}', $value, $template);
}

return $template;
}
}

// This will not work
// Fatal error: Class BadTemplate contains 1 abstract methods
// and must therefore be declared abstract (iTemplate::getHtml)
class BadTemplate implements iTemplate
{
private $vars = array();

public function setVariable($name, $var)
{
$this->vars[$name] = $var;
}
}
?>



Encapsulation :



ENCAPSULATION IN PHP CALSSES

example :
class Hide {
private $myname;
function getmyname()
{
$myname = "damodharan";
return $myname;
}
}
class damu {
private static $name;
public function name()
{
if( $this->name == null ) {
$this->name = new Hide();
}
return $this->name;
}
}
$run = new damu();
echo $run->name()->getmyname();



Poly morphism:


Polymorphism:


example code for
<?php
class Base
{
function mytext()
{
echo "hi am damu from base class ";
}
}

class myFirstClas extends Base
{
function mytext()
{
echo "hi am damu from myFirstClas class ";
}
}
class mySecondClas extends Base
{
function mytext()
{
echo "hi am damu from mySecondClas class ";
}
}
//create the object for the calss using poly marpisam

$objects = array ( $baseIns = new Base(),$myFirstClasIns = new myFirstClas(),$mySecondClasIns = new mySecondClas()
);

foreach ($objects as $object) {
echo $object->mytext();
echo "
\n";
}


Your Answers

Your Name:
Your Answers :
<> is a code tag
Preview
Enter the verification code:

Answers

anilmcmt
Sep 18 13 06:09:37
good tut,..................

vivaan
May 18 13 01:21:11
nice tutorial....

praveena
May 10 13 05:07:01
hi am damu from base class

hi am damu from myFirstClas class

hi am damu from mySecondClas class

Damodharan
May 02 13 08:04:41
Class is collection of objects ..


Ex: Student is class 

under that 
rank information , hostal information , rank information 

these all are under that student calls so its collection of objects...

sunil
May 02 13 07:35:15
what is class?

Ashutosh kumar
Apr 22 13 07:59:50
wow good

Soundar
Apr 22 13 06:48:41
Good introduction for fresher.

vinoth
Mar 24 13 11:35:14
good

Padma
Feb 27 13 07:52:31
Excellent

gowthamiraj
Feb 13 13 02:47:19
its very useful and easy to understand. thank you.

Wamp6
Feb 08 13 01:50:05
Free tutorials and reference manuals with examples for PHP,HTML,JAVASCRIPT,CSS,AJAX,JQUERY,MYSQL,NETWORKING
HTML5,OPENSOURCE,REST,SEO,SOAP.Please refer http://www.wamp6.com/

ketan patel
Feb 08 13 08:35:32
very nice formet of oops concepts!!!!!!!!!!!!!

deepak
Jan 14 13 10:28:56
good one,  
http://picspeaks.com
http://life-tweets.com
http://comp-off.com

Amesh
Dec 12 12 05:26:18
very nice...........

avnish
Nov 26 12 07:05:31


very  good

Mithilesh Kumar
Sep 23 12 06:14:19
It's really good for us 






Thnx

kashipara.in
Sep 19 12 09:19:17
www.kashipara.in

download project

kaja
Sep 05 12 09:56:25
really good

iliyas
Aug 09 12 01:10:23
nice.. :)

praveen
Jul 27 12 11:15:26
its  very nice. more useful to freshers.

Durga Prasad
Jun 27 12 01:10:01

nice explanation and thanx alot 

Ramkumar
Jun 20 12 07:23:25
super bossssssssssssssssssssuuuuuuuuuuuuuuuuu

jnanendra veer
Jun 03 12 07:54:01
Very Good Example

Dinesh
Mar 22 12 01:22:02
yes that is very good...

suresh
Feb 29 12 10:24:12
Thanks, it is very usefull. :)

Manish Patel
Feb 24 12 09:17:16
Good..that is help ful.

Shilpa
Feb 21 12 04:41:49
very nice..... n thnx alot

ikhlaque
Feb 01 12 04:51:06
Very nice.. but may be is their some explanation helpful for us.

pradeep
Jan 30 12 10:37:12
good to understand but not enough.
thanx

Jagga
Jan 26 12 12:52:35
very Nice & helpfull for us.``

gobinathan
Jan 23 12 09:47:01
hi this is simply good

Mihir
Jan 20 12 06:05:59
Good for fresher................ but  interface example is complicated understanding. 

Bhavin
Jan 19 12 10:19:17
Like This...!!! Superb

vivek
Jan 19 12 07:02:27
Its more useful to me... thanks for your guidance and sharing with us..

Shami
Jan 02 12 06:27:54
Good

Ankit
Dec 07 11 01:30:38
Nice ..
Use It...

narender
Dec 06 11 05:17:25
very good

prashant
Dec 01 11 11:38:56
yaa....nice and easy to understand

Magia..
Nov 29 11 09:17:38
Banda explanation
Banda output baharuchi.....

SRINI
Nov 25 11 08:45:01
it is very useful !!!
 but ,beginners how to understand?, please explain a simple way like your above program

mehul
Nov 15 11 02:13:02
good..but it is better when it has output...

niraj
Nov 15 11 02:11:22
Good..

Nithya
Nov 10 11 08:57:35
good but could have been even more better and ,you should give definition of polymorphism and encapsulation etc...

jegadeesh
Nov 07 11 11:18:02
It's very useful to me.......Thanks.............

Sudharshan
Oct 14 11 11:18:29
Thank you boss !! Simple superb explanation :)

Nanda
Oct 08 11 11:57:38
you can also visit for PHP tutorial
www.programmingmantra.com

zeerussia
Sep 20 11 05:43:21
Nice tutorial.thx a lot.

Raghu
Sep 08 11 06:42:28
Nice really,

Pradeep
Aug 17 11 07:27:41
Good

VIV
Aug 11 11 04:35:22
AWESOME AND SIMPLE,BUT NO O/P

kalidass
Aug 08 11 02:22:42
simple and good explanation. thanks

VINOD
Aug 04 11 07:06:11
IT NICE BUT NOT UNDERSTANDABLE......
YOU SHOULD GIVE THE EXPLANATION IN SIMPLE WORD SO THAT WE UNDERSTAND EASILY 
AND UNDERSTAND THAT HOW TO WORK OOPS CONCEPT IN PROGRAMMING LANGUAGE OR FLOW OF THE OOPS CONCEPTS SO THAT WE KNOW VERY WELL PLEASE TELL US THE FLOW TO DECLATE THE OOPS CONCEPT EASYLY ..........


THANKS........

hetal
Aug 03 11 09:01:11
it is good  explanation..thanks for that

seema
Aug 02 11 09:40:41
nice!!!

Arun
Aug 01 11 11:16:24
Pretty cool   

Ayan
Jul 28 11 10:29:04
Very nice study place.

pluskb
Jul 19 11 02:46:08
it is not good ...because it is not understanding


balamurugan
Jul 19 11 02:45:01
It really good explanation for a beginner, in very simple way. Very nice example

<a href="http://pluskb.com/">pluskb</a>

sravan
Jul 09 11 05:00:23
Nice explanation Thanx for u r explanation

koteswarachari
Jul 01 11 11:51:51
In interfaces concept, if  printing is provided it will be very easy to catch the concepts, any way these are very clear to understand.
thanks.

shweta
Jun 28 11 06:04:35
its really helpful to understand
thanks

shankar
Jun 21 11 08:55:47
nice explanation  for freshers....

shweta
Jun 20 11 06:16:15
thx a lot.......

gaurav tyagi
May 27 11 12:54:32
hi this is nice for fresher

k.sathish
May 18 11 04:16:21
Good

sahith
May 11 11 01:49:54
nice atticle

jai
May 11 11 04:18:55
Very nice code

Suraj
May 03 11 10:44:58
Good way

lokender chauhan
May 01 11 09:43:52
good need to more explanation for fresher point of view

Ravindra Singh
Mar 29 11 07:28:59
It's good to beginners.

sivanthi
Mar 27 11 01:40:21
nice tutorial thanx

Dilu
Mar 22 11 03:28:14
nice way to understand code,if u put some comment then it will better begining for freshers

Amir Shaheen
Mar 15 11 10:38:10
Great job it is a marvelous introductory picture of object oriented programmin.

vishal
Mar 15 11 06:38:39
good

vijay
Jan 20 11 11:02:17
It is not good ...because it is not understanding

srinivas
Jan 14 11 05:28:50
Good Articles help a lot.

sridhar
Dec 31 10 04:04:39
Nice thanks a lot...!

Karthic
Dec 29 10 12:05:21
Awesome Introduction

Sachin
Dec 21 10 05:29:25
really complex things for beginners make simple,really thnks

Hi, i am Jagan
Nov 26 10 12:14:58
Really this page has some useful information. Nice

sagar
Nov 22 10 12:43:23
goood one

Shiva
Nov 19 10 04:13:11
I was searching for something like this... thanks a lot...

haribabu
Oct 28 10 12:59:58
Its vry easy to understand......nice code for begginners

sap
Oct 19 10 10:46:40
Simpe Code nice

Raghav
Sep 28 10 09:37:38
Nice Article for  Beginners

Rahul dev
Sep 22 10 06:56:06
Nice intro of oops concepts.

noman
Aug 16 10 05:50:42
good

Jibin
Aug 14 10 10:39:36
Good

Adesh kumar
Aug 10 10 08:44:03
Good  Articles  for a beginner........

Ganesh
Jul 13 10 11:40:32
Nicely presented !!!

damodharan
Jun 28 10 12:54:57
ya its really good for understand the oops concept. please follow it.

Pradeepkumar Yadav
Jun 03 10 01:38:20
It really good explanation for a beginner, in very simple way. Very nice example

Pradeepkumar Yadav
Jun 03 10 01:34:56

Shalini
May 25 10 08:39:34
Easy way of understanding OOPS, when following  your samples.Nice.

Vishal Rathod
May 18 10 06:04:36
its good...

Sreeni
May 05 10 05:06:56
Nice way to make others grasp thinks easily.

Keep Going

ritesh
Apr 27 10 09:56:54
i am ritesh patel . its nice

kiruthika
Apr 12 10 03:22:11
Nice explanation

priyesh singh
Feb 11 10 12:21:43
really, very good and brief introduction of oops..

Sashi
Jan 05 10 10:17:17
Good introduction.