Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Object Oriented Programming in PHP: The Way to Large PHP Projects
Data members are defined in php using a "var" declaration inside the class, data members have no type until they are assigned a value. A data member might be an integer, an array, an associative array or even an object. Methods are defined as functions inside the class, to access data members inside the methods you have to use $this->name, otherwise the variable is local to the method.
You create an object using the new operator:
$obj=new Something;
Then you can use member functions by:
$obj->setX(5);
$see=$obj->getX();
The setX member function assigns 5 to the x datamember in the object obj (not in the class), then getX returns its value: 5 in this case.
You can access the datamembers from the object reference using for example: $obj->x=6; however, this is not a very good OOP practice. I enforce you to set datamembers by defining methods to set them and access the datamembers by using retrieving methods. You'll be a good OOP programmer if you consider data members inaccesible and only use methods from the object handler. Unfortunately PHP doesn't have a way to declare a data member private so bad code is allowed.
Inheritance is easy in php using the extend keyword.

<?php

class Another extends Something {
    var
$y;
    function
setY($v) {
        
// Methods start in lowercase then use lowercase to seperate
        // words in the method name example getValueOfArea()
        
$this->y=$v;
    }

    function
getY() {
        return
$this->y;
    }
}

?>
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
RE: OO Programming Documentationsachin puranik06/09/07 01:15
*°øÂ¥! ¿©¼º°ú Áñ±â´Â ¾ßÇÑ µ¿¿µ»ó*À¯¸®ÇÏ11/17/05 14:33
¢¾¢½100% ¹«-Á¦-ÇÑ..¼º/ÀÎ/µ¿/¿µ/»ó ´Ù¿î·Îµå~¡Ú¼º.ÀÎ.°Ô.½Ã.ÆÇ11/17/05 04:16
RE: convert PHP file to XML file Miguel García10/20/05 14:28
oops Source coding gold06/14/05 08:24
DB Classthetmgu05/13/05 06:39
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÇýÁø12/04/04 10:27
½Å.¿ë.ºÒ.·®/Ä«.µå.¿¬.ü/´ë.Ãâ/È¥ÀÚ/ÇØ.°áÇÏ´Â/¹æ.¹ý±èÇö¼­12/02/04 18:23
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÇýÁø11/26/04 04:59
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæÇý11/20/04 00:30
½Å.¿ë.ºÒ.·®.ÀÚ/´çÀÏ500/´ë.Ãâ.ºñ.¹ýÀÌÈñÁø11/19/04 00:45
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÁ¤¿¬11/16/04 18:43
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæÇý11/15/04 19:24
ÇÚµåÆù¸¸ ÀÖÀ¸¸é 10ºÐ¾È¿¡ 20¸¸¿ø ¸¸µå´Â ¹ý¼ÛÀ¯¸®06/26/04 05:27
ÇÚµåÆù¸¸ ÀÖÀ¸¸é 10ºÐ¾È¿¡ 20¸¸¿ø ¸¸µå´Â ¹æ.¹ýÁ¤´Ù·¡06/17/04 08:15
Overloading constructor (and more)Ruslan Talpa02/20/03 09:13
Searching coders for an awesome projectRedDragon01/10/03 20:00
RE: Php VS ASPCosmin12/12/02 11:11
RE: Class/Object FunctionsVinay Srivastava11/19/02 01:56
RE: Login reminderVinay Srivastava11/19/02 01:49
RE: serverside coding quiz in phpVinay Srivastava11/19/02 01:38
Serialization works in PHP4Tom Wilcoxen10/17/02 11:17
RE: Defining methods outside the classTom Wilcoxen10/17/02 11:15
RE: OOP and securitySteve Belanger10/16/02 03:26
RE: OO Programming only for large projects?Pavan Gupta09/12/02 23:27
RE: convert an object PHP to XML file Stanislav Shramko08/27/02 02:36
php object in cookiesPrabin08/14/02 17:01
serverside coding quiz in phpparul08/12/02 03:34
Session vars with PHP OOPPatrick Singcaster07/15/02 10:06
RE: Solution on overloading constructor!!! ERChristian Jul Jensen07/10/02 10:41
RE: Reference not copy?Rod K06/11/02 21:06
Reference not copy?Dan06/11/02 08:18
RE: Passing an object to another & modifyingRod K06/04/02 20:47
Defining methods outside the classemmanuel incandela06/04/02 12:04
Passing an object to another & modifyingBoombastik06/04/02 10:20
RE: OOP cheating!Haryon05/29/02 06:47
Good use of contructorsDominique Sassi05/16/02 10:32
php sessions and classesleena04/28/02 11:45
RE: OO Programmer urgently requiredshahid04/24/02 08:53
Structured vars in PHP.Sven-Erik Tiberg03/27/02 03:26
generating NLP using PHP?destri03/20/02 15:02
convert an object PHP to XML file joseph 03/12/02 13:52
RE: OOP cheating!John Stolan02/27/02 10:53
OOP cheating!Juan 02/19/02 21:26
Want to participate in an awesome oop projectFrank Nissel02/17/02 13:10
PerformanceAdrian02/04/02 09:31
Reference QueuesSebastian Deutsch02/03/02 13:47
Login reminderJayesh Prajapati02/01/02 23:40
OO Programmer urgently requiredAdam Sanders01/18/02 06:00
RE:RE: Solution for overloading constructorMarcello Junior01/14/02 15:34
Différence Function / ClassJCL01/10/02 06:21
What's the way to destroy objects?Dragón12/27/01 09:25
RE: Solution for overloading constructorAlex Kusuma Tjahjana12/19/01 05:01
OO Programming DocumentationMarc12/10/01 07:01
OO framework for web appsmogmios12/09/01 01:22
RE: OO Programming DocumentationHemant Pardesi10/30/01 05:09
Php VS ASPYasir10/30/01 04:03
warning!OerSoep10/26/01 08:51
Nice !!!!shajeed10/25/01 03:39
ERRATA 2Marcello Junior10/15/01 22:56
Solution on overloading constructor!!! ERRATAMarcello Junior10/14/01 23:53
Solution for overloading constructorMarcello Junior10/14/01 23:32
Return in Constructorsdjeus09/17/01 07:01
looking for a tutorial over phpdon munzer09/08/01 17:27
pb with unserialize a instance of classjoseph chidiac09/04/01 07:19
RE: Error with overloading constructormarco08/30/01 03:04
RE: Overloading Functionsmarco08/30/01 02:58
How to share objects once created ?Amit08/21/01 09:59
How do i access objects, once created, all acAmit08/21/01 09:47
RE: OOP feature?Frederic LEROY08/16/01 11:03
RE: PHP dont support full OOPSridhar Balasubramanian08/04/01 00:13
RE: OOP feature?Atur Shah08/03/01 02:48
RE: Class/Object Functionsanand07/30/01 05:52
class property description and constantsMichael2307/25/01 12:14
GET_CREATED_OBJECTSbombjack07/23/01 02:41
There's some good introduction made!Jesper Brunholm07/06/01 03:12
OOP feature?RAMbIS06/20/01 03:03
Event driven or not in PHP ?Nihat TUNALI06/12/01 14:58
RE: PHP dont support full OOPLarz05/31/01 16:10
OOP and securityJames Still05/31/01 06:46
RE: CONSTRUCTORS...MACL05/21/01 09:54
looking for litterature about PHP OODURAND05/19/01 05:29
RE: PHP dont support full OOPCarl Drinkwater05/11/01 03:31
RE: PHP dont support full OOPAdam Roderick05/08/01 10:43
PHP dont support full OOPJailton Oliveira05/07/01 15:30
RE: Objects and sessionsMattias Eliasson05/04/01 05:18
RE: CONSTRUCTORS...Mattias Eliasson05/04/01 04:45
need helpnarendra h n05/03/01 09:23
?PHP?Shawn Stott05/02/01 07:31
CONSTRUCTORS...Dolce04/25/01 06:58
Looping through ArraysDom04/19/01 05:43
Multiple ExtendsRichard03/19/01 06:39
RE: Objects and sessionsSonOfDad03/07/01 03:55
RE: Objects and sessionsdan donaldson03/06/01 10:14
Objects and sessionsSonOfDad03/05/01 06:28
RE: Overloading FunctionsMichael03/03/01 20:52
RE: OO Programming only for large projects?AlCap102/28/01 09:37
OO PHP & MySQLMIke02/23/01 13:51
RE: Use an object in an include fileLuis Argerich02/08/01 09:19
RE: sub-classes, objects within objectsZef Hemel02/06/01 07:53
Could have made it more dirty :)Nick01/27/01 19:14
sub-classes, objects within objectsTrevor Linton01/26/01 13:26
Use an object in an include filePatbucks01/24/01 10:39
Small mistake at the endAllard Buijze01/18/01 13:52
Overloading FunctionsApril Harry Quinones01/11/01 04:04
RE: Overriding methodsgreggory01/09/01 05:11
Serialize/Unserialize objectsAsger Henriksen01/08/01 18:59
Overriding methodsNorberto Henriques01/08/01 13:37
RE: Error????L. ARGELICH12/17/00 17:05
Class/Object FunctionsSzabó Gyula12/13/00 06:56
OO Programming only for large projects?Angel Maldonado10/17/00 09:48
Thanks...Rune Bromer10/09/00 13:45
Error with overloading constructorJeff McDonald09/10/00 18:43
The class of an objectEusebe Dollars08/31/00 06:40
Good Jobrob08/11/00 16:16
RE: Error????Luis Argerich08/10/00 18:26
Error????Sergio López Álvarez07/24/00 05:53
OO Programming DocumentationPreethi Hegde07/07/00 01:30
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.