Sunteți pe pagina 1din 46

OOPS concepts in PHP http://www.scribd.

com/doc/24094382/OOPS-concepts-in-PHP

Scribd
Upload a Document
Search Documents
Explore

Documents

Books - Fiction
Books - Non-fiction
Health & Medicine
Brochures/Catalogs
Government Docs
How-To Guides/Manuals
Magazines/Newspapers
Recipes/Menus
School Work
+ all categories

Featured
Recent

People

Authors
Students
Researchers
Publishers
Government & Nonprofits
Businesses
Musicians
Artists & Designers
Teachers
+ all categories

Most Followed
Popular

Manish Sahu

How does Scribd know my name?

We are using Facebook to personalize your experience on Scribd.

Learn More

Account

My Home
View Public Profile
My Documents
My Collections
Messages
Settings
Help
Log Out

1 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

Welcome to Scribd - Where the world comes to read, discover, and share...

We’re using Facebook to give you reading recommendations based on what your friends are sharing and the
things you like. We've also made it easy to connect with your friends: you are now following your Facebook
friends who are on Scribd, and they are following you! In the future you can access your account using your
Facebook login and password.
Learn moreNo thanks

Some of your friends are already on Scribd:

Shiv
Singh
Raghib
Suleman
Sumit
Grover
Krishna
Rai
Amol
Chandra
Marghoob
Suleman
Victor
Uday
Kv
Gautam
Arjun
Kumar
Bibhuti
Narayan

www.microsoft.com/office365 Ads by Google

/ 40

2 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

www.xilinx.com/training Ads by Google

/ 40

3 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

4 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

www.microsoft.com/office365 Ads by Google

/ 40

5 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

6 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

www.microsoft.com/office365 Ads by Google

Class Constants
It is possible to define constant values on a per-class basis remaining the same and unchangeable.
Constants differ from normal variables in that you don't use the $ symbol to declare or use them.
The value must be a constant expression, not (for example) a variable, a property, a result of a
mathematical operation, or a function call.

keyword (e.g. self, parent and static).


EXAMPLE := const constant = 'constant value';
<?php
class MyClass
{
const constant = 'constant value';

function showConstant() {
echo self::constant . "\n";
}
}

echo MyClass::constant . "\n";

$classname = "MyClass";
echo $classname::constant . "\n"; // As of PHP 5.3.0

$class = new MyClass();


$class->showConstant();

echo $class::constant."\n"; // As of PHP 5.3.0


?>

/ 40

7 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

called
One ofinthe
Its also case
biggest
possibleyouforare
annoyances
trying toto
interfaces use
ishave
having
a class/interface
to write Look
constants. a long
which
atlist
hasn't
theofinterface
needed
been defined
includesyet.
at the
documentationBybeginning
calling
for thisof each
examples.
script (one
function thefor
scripting
each class).
engine is given a last chance to load the class before PHP fails with an error.
As of PHP 5.3.0, it's possible to reference the class using a variable. The variable's value can not be a

www.microsoft.com/office365 Ads by Google

Constructors and Destructors

/ 40

8 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

The destructor
method
search for
callthethis
old-style
method
methodwill
constructor
on beeach
called
newly-created
function,
as soon by
as object,
all
thereferences
nameso of
it isthe
to
suitable
class.
a particular
Effectively,
for anyobject
initialization
itare
means
removed
that the
or
objectcase
only
when the
mayobject
that
needwould
isbefore
explicitly
have
it iscompatibility
used.
destroyed orissues
in anyisorder
if theinclass
shutdown
had a method
sequence.named __construct() which
was used for different semantics.

$this->name = "MyDestructableClass";
}

function __destruct() {
print "Destroying " . $this->name . "\n";
}
}

$obj = new MyDestructableClass();


?>

Like constructors, parent destructors will not be called implicitly by the engine. In order to run a parent

/ 40

9 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

www.microsoft.com/office365 Ads by Google

Visibility
The visibility of a property or method can be defined by prefixing the declaration with the keywords
public, protected or private. Class members declared public can be accessed everywhere. Members
declared protected can be accessed only within the class itself and by inherited and parent classes.
Members declared as private may only be accessed by the class that defines the member.

Property Visibility
Class properties must be defined as public, private, or protected. If declared using var without an
explicit visibility keyword, the property will be defined as public.
Note: The PHP 4 method of declaring a variable with the var keyword is still supported for
compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its
usage would generate an E_STRICT warning.
<?php

/ 40

10 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

echo
* Define
public
$objecho
->
MyClass
protected
$public
$this->
MyClass2 =;public
'Public'
// Fatal
; ; Error
echo
*/ protected
$objecho
->private
$this;->protected
$protected = 'Protected'
// Fatal ;
Error ;
private
echo$private
$this->private
= 'Private'
; ;

/ 40

11 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

12 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

13 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

14 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

15 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

16 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

17 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

18 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

19 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

20 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

21 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

22 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

23 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

24 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

25 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

26 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

27 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

28 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

29 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

30 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

31 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

32 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

33 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

34 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

35 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

/ 40

36 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

OOPS concepts in PHP


Download this Document for FreePrintMobileCollectionsReport Document
This is a private document.
/ 40

37 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

Info and Rating

shimpu_84 Follow
Like 17 people like this. Be the first of your friends.

Share & Embed

Related Documents

PreviousNext

1.
p.

p.

p.

2.
p.

p.
/ 40

38 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

p.

3.
p.

p.

p.

4.
p.

p.

p.

5.
p.

p.
/ 40

39 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

p.

6.
p.

p.

p.

7.
p.

p.

p.

8.
p.

p.
/ 40

40 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

p.

9.
p.

p.

p.

10.
p.

p.

p.

11.
p.

p.
/ 40

41 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

p.

12.
p.

p.

p.

13.
p.

p.

p.

14.
p.

p.
/ 40

42 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

p.

15.
p.

p.

p.

16.
p.

p.

p.

17.
p.

p.
/ 40

43 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

More from this user

PreviousNext

1.
7 p.

56 p.

12 p.

2.
40 p.

1 p.

25 p.

Recent Readcasters

Bhimrav

Subash

Shailendra

Add a Comment

/ 40

44 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

share:
Characters: 400

Ankit Mishraleft a comment

comment

11 / 08 / 2010
Reply

www.microsoft.com/office365 Ads by Google


Upload a Document
Search Documents

Follow Us!
scribd.com/scribd
twitter.com/scribd
facebook.com/scribd

About
Press
Blog
Partners
Scribd 101
Web Stuff
Scribd Store
/ 40Support

45 of 46 5/31/2011 2:26 PM
OOPS concepts in PHP http://www.scribd.com/doc/24094382/OOPS-concepts-in-PHP

FAQ
Developers / API
Jobs
Terms
Copyright
Privacy

Copyright © 2011 Scribd Inc.


Language:
English

/ 40

46 of 46 5/31/2011 2:26 PM

S-ar putea să vă placă și