.Net Framework, Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML

Ado.netAsp.Net 2.0SQLC-SharpXMLFrameworkIISXMLWebServiceArchitecture
UMLProject ManagementSDLCMethodologiesDesign PatterenOOPWCF.Net RemotingWWF
MVPMVCSilver LightN-HibernateAjaxJ-QuerySEO-MarketingSite MapPhp

OOPS in php programming

Object oriented php development.

Inhertance, Abstraction, Encapsulation, functiona overloading in php.
We have expert php mysql developer in mumbai india, We can provide Php JQuery, php with mysql, php with ajax, php webservice, SEO compitable php design and more. Please contact us to know more about our service.
Php is a complete object oriented programming language. Now lets look how we can make object oriented php design

How to use/make class in php
Class design in php
<?php
1:
2:/**
3:Created by Arindam Chakraborty on 2nd Oct. 2009
4:
5:**/
6:
7:
8:class car {
9:
10: // explicitly adding class properties are optional - but is good practice
11: var $name;
12:
13: function __construct($car_name) {
14:
15: $this->name = $car_name;
16: }
17:
18:
19: public function get_name() {
20:
21: return $this->name;
22:
23: }
24:
25:
26: protected function set_name($new_name) {
27:
28: if (name != "Honda Civic") {
29: $this->name = strtoupper($new_name);
30: }
31:
32: }
33:
34:
35:}
36:
37:// 'extends' is the keyword that enables inheritance
38:class honda extends car {
39:
40:
41: protected function set_name($new_name) {
42:
43: if ($new_name == "Honda City") {
44: $this->name = $new_name;
45: }
46: else if($new_name == "Honda Civic") {
47: parent::set_name($new_name);
48: }
49:
50: }
51:
52: function __construct($car_name) {
53:
54: $this->set_name($car_name);
55: }
56:
57:
58:
59:}
60:
61:
62:
63:?>
64:
How to make inheritance in php
Inheritance in php
class car {
1:
2:}
3:
4:class maruti extends car {
5:
6:}
7:
8:So here 'extends' is the keyword that enables inheritance in php.
9:
How to make a new class object in php ?
How to create new object in php
1:// i am a creating a new car object
2:$objCar = new car("Stefan Mischook");
3:
4:// calling a function of that $objCar
5:echo "Calling a function" . $stefan->get_name();
6:
Abstract class in php
Abstract class in php
<?php
1:abstract class AbstractClass
2:{
3: // Force Extending class to define this method
4: abstract protected function getValue();
5: abstract protected function prefixValue($prefix);
6:
7: // Common method
8: public function printOut() {
9: print $this->getValue() . "\n";
10: }
11:}
12:
13:class ConcreteClass1 extends AbstractClass
14:{
15: protected function getValue() {
16: return "ConcreteClass1";
17: }
18:
19: public function prefixValue($prefix) {
20: return "{$prefix}ConcreteClass1";
21: }
22:}
23:
24:class ConcreteClass2 extends AbstractClass
25:{
26: public function getValue() {
27: return "ConcreteClass2";
28: }
29:
30: public function prefixValue($prefix) {
31: return "{$prefix}ConcreteClass2";
32: }
33:}
34:
35:$class1 = new ConcreteClass1;
36:$class1->printOut();
37:echo $class1->prefixValue('FOO_') ."\n";
38:
39:$class2 = new ConcreteClass2;
40:$class2->printOut();
41:echo $class2->prefixValue('FOO_') ."\n";
42:?>
43:
Leave your comment.
Name
Email
Comments
Tell Us8959+5 =

Reduce your Dialy IT Cost, Consult with us
Stay healthy in recession

Advertisement
Sponsored by

Privacy Policy ©2009 ETG Consultancy, All Rights Reserved Terms & Conditions
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML