473,657 Members | 2,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New to OO programming

Ive been using PHP 4 for about 3.5 years now, and havnt messed with
objects and classes for whatever reason, however I know I need to start
using them. With someone who has no class/object programming
experience, php's manual is quite dull and leaves me scratching my
head. Is there a more indepth manual or tutortial somewhere that can
explain everything, and more importantly... I cant figure out why and
when an object/class would be used? Im also switching to PHP 5. Thanks.

Mar 8 '06 #1
6 1454
OOP isn't a catch all for everything. For larger application
development it is a godsend, though.

PHP5 follows most of the OOP principles, and resembles java in many
ways. Any book, tutorial, information on Object Oriented Programming
will be relevent to PHP's Object model. There are only a few
exceptions between PHP5 and general OO models that i've run into in the
past (or more precisely, frustration at single inheritance)

Generally, however, objects are used when you have a lot of code that
is similar between projects or other entities in the project, such as
User's information, Database connections, Shopping carts, etc etc. All
those things are pretty much the same between projects, and can be
extended to do more for any specific application.

I wish i could provide a good resource for you, but i've yet to find
one myself.

Mar 8 '06 #2
Try http://www.tonymarston.co.uk/php-mys...seobjects.html and
http://www.tonymarston.co.uk/php-mys...eobjects2.html

For a more advanced version you can download and view the code in my sample
application at http://www.tonymarston.net/php-mysql...plication.html

You might also find
http://www.tonymarston.co.uk/php-mys...-heretics.html rather
interesting.

--
Tony Marston

http://www.tonymarston.net

"gardnern" <na****@factory 8.com> wrote in message
news:11******** **************@ v46g2000cwv.goo glegroups.com.. .
Ive been using PHP 4 for about 3.5 years now, and havnt messed with
objects and classes for whatever reason, however I know I need to start
using them. With someone who has no class/object programming
experience, php's manual is quite dull and leaves me scratching my
head. Is there a more indepth manual or tutortial somewhere that can
explain everything, and more importantly... I cant figure out why and
when an object/class would be used? Im also switching to PHP 5. Thanks.

Mar 9 '06 #3
I agree - the manual is pretty dull, especially when you don't
understand the whole purpose behind using OOP.

Richard was right when he said "For larger application development it is
a godsend, though." One reason why OOP is the way to go when developing
larger applications is because it allows you to focus on one particular
part of the application at a time, instead of trying to constantly keep
the whole big picture in your head.

For example, let's say you're developing a shopping cart. Think of the
cart itself as an object - a real world physical object, like a cart in
a grocery store. What purpose does the cart serve? It holds items. On
a website, a cart needs to be able to receive and remove items. So your
initial class would probably start out something like this (I'll do this
with PHP4 for now for the sake of simplicity):

class cart {

var $items = array(); // This will hold all the items in the cart

function addItem($itemNo , $qty) {
if(isset($this->items[$itemNo])) {
$this->items[$itemNo]['qty'] += $qty;
} else {
$this->items[$itemNo]['qty'] = $qty;
}
}

function removeItem($ite mNo, $qty) {
if(isset($this->items[$itemNo])) {
$this->items[$itemNo] -= $qty;
}
}
}

Now, what you have is all the code that affects the shopping cart in one
place. You add properties and methods (vars and functions) based on what
functionality you want your cart to have. For example, you'll probably
want to add a displayContents () function for users to view the contents
of the cart.

The items you put in the cart can also be objects with properties such
as price, weight, item number, and name (although you'd need to do your
addItem function a little differently than I did). This will make it
easy to access these properties when you display the cart contents.
($this->items[$itemNo]->price) or something to that effect.

While PHP 5 has far superior OOP capabilities than PHP 4, it is also
much more complex. There's a book by W.J. Gilmore called "Beginning PHP
5 and MySQL: From Novice to Professional". While this wasn't the best
PHP book I've read, it did do a good job of explaining OOP in PHP 5.

Hope this helped!

Scott

gardnern wrote:
Ive been using PHP 4 for about 3.5 years now, and havnt messed with
objects and classes for whatever reason, however I know I need to start
using them. With someone who has no class/object programming
experience, php's manual is quite dull and leaves me scratching my
head. Is there a more indepth manual or tutortial somewhere that can
explain everything, and more importantly... I cant figure out why and
when an object/class would be used? Im also switching to PHP 5. Thanks.

Mar 9 '06 #4
Thanks for all the replies, some great info here. Ill read through your
site Tony, and Ill be sure to check out that book Scott. I have W.J.
Gilmores book called "PHP and E-Commerce: From Novice to Professional"
and found it helpfull, so Im sure this one will too. Thanks again.

Mar 10 '06 #5
Scott <no****@nospam. com> wrote:
I agree - the manual is pretty dull, especially when you don't
understand the whole purpose behind using OOP.
Hope this helped!

Scott


Excellent precis. Thank you.

Simon

--
Stupendous Tales
www.stupendoustales.com
Speculative Fiction, Pulp Dreams
Mar 10 '06 #6
Glad you liked it. The benefits of OOP were a bit hazy to me until I
started thinking about it from the physical world aspect.

Scott

si****@nospam.c om wrote:
Scott <no****@nospam. com> wrote:
I agree - the manual is pretty dull, especially when you don't
understand the whole purpose behind using OOP.
Hope this helped!

Scott


Excellent precis. Thank you.

Simon

Mar 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2917
by: Martin | last post by:
When was inheritance intruduced into object oriented programming? More generally, does anyone know or have any sources on when the different features were introduced into object oriented programming?
12
8466
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now I really want to get back into it as I see a point with GNU/Linux. I want to get my old skills back and write something or help on some projects etc. I need some good books. I used to have one called "A Book On C", but sold it,
3
2472
by: user | last post by:
Hi all, At the outset, I regret having to post this slightly OT post here. However, I strongly feel that people in this group would be the best to advise me on my predicament. I am working as a QA in an MNC in India, since I graduated in September 2003. I am working in a QA role which requires me to do some Winrunner automation, and modifying/creating a framework in Perl for Automated Regression Testing of some command Line utilities...
134
7963
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've increasingly been using scripting languages (especially Python and Bourne shell) which offer the same speed and yet are far more simple and safe to use. I can no longer understand why anyone would willingly use C to program anything but the lowest...
7
4945
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already developed significant content for the C programming language that is available at: https://www.securecoding.cert.org/ by clicking on the "CERT C Programming Language Secure Coding Standard"
30
32235
by: Jakle | last post by:
I have been googling, but can seem to find out about C GUI libraries. My main platform is Windows, but it would be nice to find a cross platform library. I've been programming with php, which has a C/C++ syntax structure, but want to move on to compliled languages. I was all ready to go with C++ and wxWindows, but I'm applying for an entry level programming possition. They use their own propriatary language, with
47
5921
by: Thierry Chappuis | last post by:
Hi, I'm interested in techniques used to program in an object-oriented way using the C ANSI language. I'm studying the GObject library and Laurent Deniau's OOPC framework published on his web site at http://ldeniau.web.cern.ch/ldeniau/html/oopc/oopc.html. The approach is very instructive. I know that I could do much of this stuff with e.g. C++, but the intellectual challenge of implementing these concepts with pure ANSI C is relevant to...
111
5525
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks in advance! -entengk
14
3283
by: deko | last post by:
For building Windows desktop apps, the clear favorite is C#. But my clients can't afford to buy Microsoft products. So I need to develop software for Linux users and web applications. In the open source world, what is the programmer's language of choice? Judging by the number of members in each of these http://www.google.com/Top/Computers/Programming/Languages/Open_Source/ user groups, it looks like the top 3 open source languages...
17
4702
by: CoreyWhite | last post by:
I bought this book years ago, when I was just learning C++. Since then I've gone through every math course offered at my college, taken courses on coding C & thinking in terms how how to make the smallest tightest algorithms to preform specific functions. I've also grown and matured a lot, and am wiser and older. I'm reading through the C+ + Programming Language, Third Edition now, and I can actually understand it. I can understand it...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.