I have come from a QBASIC to VFP to VC++ to PHP (VFP and PHP are my primary 
languages), so I'll try to clear it up a bit.

In VFP, there is no constructor.  I believe that the equivalent is the 
init() method.  The init() method, or the constructor (in PHP, C++, etc) 
are useful for doing stuff that needs to be done when an object is 
created.  Likewise in true object oriented languages (PHP is not one of 
them yet), there is a Destructor that is called when an object goes out of 
scope or is deleted.  In VFP, there is a Destroy() method to simulate this 

In VFP, there is the notion of Public, Private, and Hidden properties.  PHP 
does not yet support this behavior.  In PHP, especially since it is such a 
loosely typed language, you can add and remove properties on the 
fly.  Generally when programming in PHP, I like to identify private 
properties and methods by placing a single underscore before their 
name.  This makes it clear for someone using the class not to ever 
reference these entities.

If you want to see a neat example of object oriented programming in action 
(not that I like M$ or anything), check out how the Microsoft Foundation 
Classes (MFC) work.  They effectively demonstrate public and private class 
members, inheritance, constructors, destructors, parent objects, etc...

Hope it Helped...

-Jason Garber

At 09:10 AM 11/25/2001 -0400, Miles Thompson wrote:
>Not such a useless explanation at all, in fact a damned good one. Tight & 
>concise, and you immediately related the functions to code examples, along 
>with an easy-to-visualize object, the chair.
>But I have two questions:
>1. Why is a constructor class needed? My OO background is Visual FoxPro, 
>and all it requires is a declaration of  the class, it' methods and properties.
>2. Are the chairs properties exposed, or are they private? You use 
>functions to both set and retrieve them, which implies that they are 
>private.  Even so, PHP's syntax is much cleaner than the tortured syntax 
>used in VB.
>Miles Thompson
>At 03:28 AM 11/25/2001 -0800, you wrote:
>>On Sun, 25 Nov 2001, Rudi Ahlers wrote:
>> > Can anyone explain classes to me please? On many sites have I seen 
>> classes,
>>There are people earning PHD's while explaining classes.  I know your
>>question originates from using PHP, and this is a PHP general mailing list
>>... but your question is just a tad too general for this list.
>> > I'm not sure how these work, or how to use them. I'm still learning about
>>Classes aren't unique to PHP.  You need to learn a true object-oriented
>>programming language (C++, Java, ... etc.) to really learn classes.
>>Truly gifted individuals can learn object-oriented programming w/o too
>>much help, but they'd first have a firm grip on programming.  I'd expect
>>the average, novice programmer to need a good amount of help learning &
>>understanding objecte-oriented programming ...  like that attained from a
>>University, a good High School, or a lot of independent study and time
>>experimenting with code.
>>That said ...
>>You weren't completely missing the boat with your analogy of a class to a
>>variable, but in the same breath, that idea is totally missing the boat (I
>>can see from where you're coming, and to where you're headed).  Classes
>>are an IDEA.  They're not actually anything.  They're the definition of
>>private and public data members and methods that should make up an object.
>>When a class is instantiated, an object is created with the defined data
>>members and methods available.  You can then use the objects' methods to
>>set, get, alter, or otherwise interact with its data members, or to simply
>>perform a set of related operations.  <Insert a couple semesters of theory
>>here.> That's my feeble attempt to explain classes.  It's abstract, I
>>know, and possibly not a help at all.  But it's because of the paragraph
>>above this one.
>>Let's look at some petty code:
>>class chair{
>>         // DATA
>>         var num_legs;
>>         var color;
>>         var num_arms;
>>         // METHODS
>>         function chair( $legs = 3, $arms = 0 ){ //CONSTRUCTOR
>>                 $this->num_legs = $legs;
>>                 $this->num_arms = $arms;
>>         }
>>         function setLegs( $legs ){
>>                 $this->num_legs = $legs;
>>                 return;
>>         }
>>         function getLegs( ){
>>                 return $this->num_legs;
>>         }
>>         // ... *clip* ...
>>Above is the [incomplete] definition of a chair class.  As you can see,
>>the class is useless.  But you can instantiate the class, and create a
>>useable object ... you can now create a chair.
>>$myChair = new chair( 4, 2 );
>>Now I have a chair [object] with 4 legs and 2 arms, called $myChair.
>>Let's have the chair tell us how many legs it has ...
>>$numLegsOnMyChair = $myChair->getLegs();
>>print( "My Chair has $numLegsOnMyChair legs." );
>>Lets change how many legs the chair has ...
>>$myChair->setLegs( 7 ); // very odd, seven-legged chair
>>We should have a chair with 7 legs now, instead of 4.  Prove it ...
>>$numLegsOnMyChair = $myChair->getLegs();
>>print( "My Chair has $numLegsOnMyChair legs." );
>>(As you alluded to previously, the object $myChair is seemingly a variable
>>that has access to scripts ... but I hope you see now that $myChair is an
>>object with methods and data members, not a variable.)
>>That's very simple, and not too useful.  Which brings me to the next
>>point.  Knowing object-oriented programming is to know when and when not
>>to use it (especially with PHP).  I don't need a class definition and an
>>object for a one-time use 7-legged chair.  But I may need a class
>>definition if I were making many complete graph data structures, each with
>>a number of nodes equal to a unique number in the Fibonacci sequence.  I
>>wouldn't want to re-code the basic logic of a complete graph over and over
>>for each graph.  I could just instantiate graph objects, each with
>>different numbers of nodes, much like I did with the chair, above.
>>         g.luck,
>>         ~Chris                           /"\
>>                                          \ /     September 11, 2001
>>                                           X      We Are All New Yorkers
>>                                          / \     rm -rf /bin/laden
>>PHP General Mailing List (
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>PHP General Mailing List (
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]

PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to