473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Classes and objects - please explain

Hey all,

PHP is my first serious programming language (have some exp w/
javascript), so this notion of classes and objects confuses me. What's
a good way for me to understand this?

-cyktor

Nov 2 '06 #1
17 1321
Technically speaking, in JavaScript you don't have classes, but only
objects. Remember that it is a prototype based language.
Anyway, JavaScript won't help you much with understanding classes and
objects. Read some OOP books. But before you do, teach yourself some
procedural programming. Because *some* ain't enough. And, in the end,
most of the time you don't actually need OOP to go from A to B.

Nov 2 '06 #2
Following on from 's message. . .
>Hey all,

PHP is my first serious programming language (have some exp w/
javascript), so this notion of classes and objects confuses me. What's
a good way for me to understand this?

-cyktor
Read a book?

--
PETER FOX Not the same since the e-commerce business came to a .
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Nov 2 '06 #3
By procedural programming, do you mean C? Please give me some
suggestions for procedural languages to learn.

-cyktor

Nov 2 '06 #4
A great text for PHP in general and OOP in particular is "Beginning PHP 5
and MySQL" by Jason Gilmore. A trip to the local bookstore or amazon.com
would provide you with more information than a reply in this forum.

Harley

P.S. If you want to use OOP skip PHP-4 and go directly to PHP-5 which has
much more functional OOP support.

<cy****@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hey all,

PHP is my first serious programming language (have some exp w/
javascript), so this notion of classes and objects confuses me. What's
a good way for me to understand this?

-cyktor

Nov 2 '06 #5
cy****@hotmail.com wrote:
Hey all,

PHP is my first serious programming language (have some exp w/
javascript), so this notion of classes and objects confuses me. What's
a good way for me to understand this?

-cyktor
You can just look at the php manual:

version 4
http://www.php.net/manual/en/language.oop5.php

version 5
http://www.php.net/manual/en/language.oop.php

You can also just Google for OOP Tutorial

OOP and OOD terminology are the same in any language. Some languages
implement more of OOP\OOD than others.

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ____________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Nov 2 '06 #6
cy****@hotmail.com wrote:
By procedural programming, do you mean C? Please give me some
suggestions for procedural languages to learn.

-cyktor
In most cases, an OOP language is also procedural. OOP is, at its
core, a fancy way to write modular and reusable procedural code,
because within all the layers of classes and functions, you still have
individual lines of code saying:
assign variable X
if something, then something
do this
do that

^- that is procedural code.

As for learning OOP, oh boy, where to begin? While it isn't strictly
an OOP book, I highly recommend going and getting a copy of The
Pragmatic Programmer and reading it cover to cover, and then once more
just to make sure you didn't miss anything. It won't teach you the
nuts and bolts of OOP, but it will lay a solid foundation of principles
that will help you understand the *why* of OOP in addition to the *how*.

Nov 2 '06 #7
A class is more specific name for the generic idea of an object.

Basically, it allows you to put code and data into a container and
tell the container to act on something and give me back a response. A
real example is a remote control which accepts the pressing of the
"power" key and then tells the TV to turn on/off.

YOu do need to get a basic book on object design if you plan to use
classes.

On 2 Nov 2006 07:17:31 -0800, cy****@hotmail.com wrote:
>Hey all,

PHP is my first serious programming language (have some exp w/
javascript), so this notion of classes and objects confuses me. What's
a good way for me to understand this?

-cyktor
Nov 2 '06 #8
This is a basic OO tutorial

http://www.aonaware.com/OOP1.htm

On 2 Nov 2006 07:17:31 -0800, cy****@hotmail.com wrote:
>Hey all,

PHP is my first serious programming language (have some exp w/
javascript), so this notion of classes and objects confuses me. What's
a good way for me to understand this?

-cyktor
Nov 2 '06 #9

cy****@hotmail.com wrote:
By procedural programming, do you mean C? Please give me some
suggestions for procedural languages to learn.
PHP without objects and classes is a good enough starting point to
learn procedural programming:

$howManyHats = 4;
$howManyHats = $howManyHats + 3;
setcookie("howManyHats", $howManyHats);

Things happen one at a time, straight down the page. You can use
functions, which means the code goes into those code blocks, but it is
still pretty straightforward.

With objects, you'd suddenly have some variables that are maybe set
inside of objects, and therefore the code is no longer so
straightforward. If HatObject sets a variable called $yardsOfCloth in
its constructor (let's say a value of 34):

$hatObject = new HatObject();
$clothInYards = $hatObject->getYardsOfCloth();
echo $clothInYards; // shows 34

Nov 2 '06 #10

David wrote:
A class is more specific name for the generic idea of an object.
Possibly you meant the opposite of this? An object is one specific
instance of a class. A class is a template for making certain kinds of
objects, but each object made from that class is its own specific
variable.

>
Basically, it allows you to put code and data into a container and
tell the container to act on something and give me back a response. A
real example is a remote control which accepts the pressing of the
"power" key and then tells the TV to turn on/off.

YOu do need to get a basic book on object design if you plan to use
classes.

On 2 Nov 2006 07:17:31 -0800, cy****@hotmail.com wrote:
Hey all,

PHP is my first serious programming language (have some exp w/
javascript), so this notion of classes and objects confuses me. What's
a good way for me to understand this?

-cyktor
Nov 2 '06 #11
All this explanations, OOP at a glance, seem futile to me. OOP ain't
that simple. So a book is recommended. Not only about classes and
objects, but about interfaces, inheritance, polymorphism, and so on and
so forth. I'm working with classes and objects for 3 years now and I
still have problems with object oriented thinking.

And books, well... I can't think of a suggestion. My first language was
C++, and my first OOP steps were from "Jamsa's C/C++ Programmer's
Bible". The rest is history :-D

And, btw, cyk...@hotmail.com, learn a true programming language (not
JavaScript), such as C or C++, start with the beginning (procedural
programming) and then think of OOP. It's not something you learn in 24
hours.

Nov 3 '06 #12
whiskey wrote:
And, btw, cyk...@hotmail.com, learn a true programming language (not
JavaScript),
JavaScript /is/ a true programming language

http://javascript.crockford.com/javascript.html

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Nov 3 '06 #13
In article <11**********************@m73g2000cwd.googlegroups .com>,
al************@gmail.com (whiskey) wrote:
All this explanations, OOP at a glance, seem futile to me. OOP ain't
that simple. So a book is recommended. Not only about classes and
objects, but about interfaces, inheritance, polymorphism, and so on and
so forth. I'm working with classes and objects for 3 years now and I
still have problems with object oriented thinking.

And books, well... I can't think of a suggestion. My first language was
C++, and my first OOP steps were from "Jamsa's C/C++ Programmer's
Bible". The rest is history :-D
PHP 5 Objects, Patterns, and Practice.
Matt Zandstra, Apress
ISBN 1-59059-380-4

But it assumes existing knowledge of PHP and of procedural programming.
Nov 3 '06 #14
Pedro Graca wrote:
JavaScript /is/ a true programming language
Sure it is true, rather a true *scripting* language.
One friend o'mine once said: "Life's hard without pointers..." :-)

Rafe Culpin wrote:
But it assumes existing knowledge of PHP and of procedural programming.
Of course, that's what I'm trying to say. Learn to do it in a
procedural way, and then start to better organise your application as
whole by using an OO aproach.

Nov 3 '06 #15
whiskey wrote:
Technically speaking, in JavaScript you don't have classes, but only
objects. Remember that it is a prototype based language.
Anyway, JavaScript won't help you much with understanding classes and
objects. Read some OOP books. But before you do, teach yourself some
procedural programming. Because *some* ain't enough. And, in the end,
most of the time you don't actually need OOP to go from A to B.
No, you don't *need* OOP. But you don't generally *need* structured
programming, either. You can do quite well with spaghetti code.

However - OOP is a means to build code that, if properly designed, is
more reusable and more maintainable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 4 '06 #16
whiskey wrote:
All this explanations, OOP at a glance, seem futile to me. OOP ain't
that simple. So a book is recommended. Not only about classes and
objects, but about interfaces, inheritance, polymorphism, and so on and
so forth. I'm working with classes and objects for 3 years now and I
still have problems with object oriented thinking.

And books, well... I can't think of a suggestion. My first language was
C++, and my first OOP steps were from "Jamsa's C/C++ Programmer's
Bible". The rest is history :-D

And, btw, cyk...@hotmail.com, learn a true programming language (not
JavaScript), such as C or C++, start with the beginning (procedural
programming) and then think of OOP. It's not something you learn in 24
hours.
OOP is quite easy - but it's a different way of thinking. And the longer
you've been doing procedural programming, the harder time you'll
probably have getting a handle on it.

Simply put, variables have states (values). Functions have behavior
(they do things). Objects have both states and behavior. You can save
one or more values in it (depending on how it's designed) and it has
behavior as defined by its public function.

Really, even an integer can be considered a class. You can instantiate
it to get a variable (object). It has state (it's value) and behavior
(add, subtract, etc.). Classes are just a way of extending what the
language predefines into something the programmer can define.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 4 '06 #17
whiskey wrote:
Pedro Graca wrote:
>>JavaScript /is/ a true programming language

Sure it is true, rather a true *scripting* language.
One friend o'mine once said: "Life's hard without pointers..." :-)

Rafe Culpin wrote:
>>But it assumes existing knowledge of PHP and of procedural programming.

Of course, that's what I'm trying to say. Learn to do it in a
procedural way, and then start to better organise your application as
whole by using an OO aproach.
Don't let the "script" in Javascript fool you. Javascript is as much a
scripting language as PHP. Both are interpreted - one by the browser,
one by the server.

And yes, Javascript is a true programming language. OTOH, HTML is a
true scripting language.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 4 '06 #18

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

Similar topics

18
by: vrillusions | last post by:
I've been using functions since I first started using php, but I've been hearing more and more about classes, which I never really looked at that much. I understand the whole OO programming...
3
by: Logan K. | last post by:
What is a PHP class? I've seen a lot of talk about these and how they can help you out, but I've never seen a very good explanation. I've been working with PHP for just over 6 months and usually...
145
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
1
by: Aidan Glendye | last post by:
Hi, I am trying to store various objects within session. Due to the site being hosted in a web farm we are going to have to use either State Server or SQL Server to persist the data in...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
4
by: Chris F Clark | last post by:
Please excuse the length of this post, I am unfortunately long-winded, and don't know how to make my postings more brief. I have a C++ class library (and application generator, called Yacc++(r)...
4
by: christophe.gosiau | last post by:
Hi everybody, I have the following problem: For an application, I made 2 classes: Order and Ticket In the Order object I store an array with Ticket objects. so far so good, now I needed the Order...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.