Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
OOPS concepts in PHP

OOPS concepts in PHP



|Views: 36,631 |Likes:
Published by Sanjog Srivastava

More info:

Published by: Sanjog Srivastava on Dec 15, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





Starting with PHP 5, the object model was rewritten to allow for better performance and more features.This was a major change from PHP 4. PHP 5 has a full object model.Among the features in PHP 5 are the inclusions of visibility, abstract and final classes and methods,additional magic methods, interfaces, cloning and typehinting.PHP treats objects in the same way as references or handles, meaning that each variable contains anobject reference rather than a copy of the entire object. See Objects and References
Classes and Objects
The Basics
Class Constants
Autoloading Classes
Constructors and Destructors
Object Inheritance
Scope Resolution Operator (::)
Static Keyword
Class Abstraction
Object Interfaces
Object Iteration
Magic Methods
Final Keyword
Object Cloning
Comparing Objects
Type Hinting
Late Static Bindings
Objects and references
Object Serialization
Every class definition begins with the keyword class, followed by a class name, followed by a pair of curly braces which enclose the definitions of the class's properties and methods.The class name can be any valid label which is a not a PHP reserved word. A valid class name startswith a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.A class may contain its own constants, variables (called "properties"), and functions (called"methods").
<?phpclassSimpleClass{ // property declaration public$var='a default value';  // method declaration public functiondisplayVar() { echo$this->var; }}?> 
The pseudo-variable
is available when a method is called from within an object context.
is areference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is calledstaticallyfrom the context of a secondary object).
<?phpclassA{functionfoo(){if (isset($this)) {echo'$this is defined (';echoget_class($this); echo")\n";} else {echo"\$this is not defined.\n";}}}classB{functionbar(){ // Note: the next line will issue a warning if E_STRICT is enabled. A::foo(); }
}$a= newA(); $a->foo(); // Note: the next line will issue a warning if E_STRICT is enabled.A::foo(); $b= newB(); $b->bar(); // Note: the next line will issue a warning if E_STRICT is enabled.B::bar(); ?> 
To create an instance of a class, a new object must be created and assigned to a variable. An object willalways be assigned when creating a new object unless the object has a constructor defined that throwsan exception on error. Classes should be defined before instantiation (and in some cases this is arequirement).In the class context, it is possible to create a new object by new self and new parent.When assigning an already created instance of a class to a new variable, the new variable will accessthe same instance as the object that was assigned. This behaviour is the same when passing instances toa function. A copy of an already created object can be made by cloning it.
<?php$assigned=$instance; $reference=&$instance; $instance->var='$assigned will have this value'; $instance=null;// $instance and $reference become null var_dump($instance); var_dump($reference); var_dump($assigned); ?> 
A class can inherit the methods and properties of another class by using the keyword extends in theclass declaration. It is not possible to extend multiple classes; a class can only inherit from one baseclass.The inherited methods and properties can be overridden by redeclaring them with the same namedefined in the parent class. However, if the parent class has defined a method as final, that method maynot be overridden. It is possible to access the overridden methods or static properties by referencingthem with parent::

Activity (216)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
ajayksy added this note
Excellent tutorial with good examples..Great!!!!!!!
Prasad Durga added this note
thank u . and this is my request plz upload more functions.
Toaster97 liked this
Parsetty Ravinder added this note
tanks its very helpful
Venkata Ramesh liked this
Jagan Kotagiri added this note
Saravanan Varathappan added this note
really superb....
Durai Srinivasan added this note
thanks. good tutorial.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->