You are here: Re: Classes, don't follow. « PHP Programming Language « IT news, forums, messages
Re: Classes, don't follow.

Posted by Colin Fine on 10/13/05 22:15

Samuel wrote:
> In general, OOP is more or less what your example shows. The class
> defines what the object is and can do, while the object actually *is*
> something (an instance of the class) and *does* something. See if this
> pseudocode helps...
>
>
> Class Dog
> {
> var race;
> var food_it_likes;
>
> function Bark
> {
> ...
> }
>
> function Poop
> {
> ...
> }
>
> } //End Dog Class
>
>
> //You have just defined what a dog is and can do, so that you can have
> multiple dogs doing stuff. Then, in your program...
>
> Dog Vincent;
> Dog Toby;
>
> Toby.race = "Scottish Terrier";
> Toby.food_it_likes = "Tasty Chicken";
> Vincent.race = "Chiuaua";
> Vincent.food_it_likes = "Human Flesh";
>
> Vincent.Bark;
> Toby.Poop;
>
> //You now *actually* have two dogs who can bark and poop. One is
> barking (Vincent the scary assasin little chiuaua), and the other is
> pooping (Toby the elegant black Scottish).
>
> Greetings
>
This is obviously not PHP syntax (Samuel even says it's pseudocode), but
it could easily mislead people into a mistake that I kept making when I
started:

The PHP for some of those lines might be

$Vincent->race = "Chihuahua";

but

$Vincent->Bark();

If you leave out the parens, it's an (undeclared) property (variable)
not a method (function).

Colin

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация