Reply to Trying to get to grips with OOP! Classes.

Your name:

Reply:


Posted by Simon Dean on 10/24/01 11:34

Hello,

Im hoping you can help me.

Im, probably not that advanced with PHP, well, I probably am, but with a
memory like a sieve, I rarely take in information...

But, Im just considering some OOP using PHP's Classes.

Seems quite handy so far, already generated a Login class and it does
tidy things up quite considerably. It means things like Error Logging
and tracking is neatly handled... pass in a Login and Password, say
"Login" and get any error messages back...

Nice.

Though too simple for my tastes. Im looking at ways to expand this,
mainly for database queries and updates... that kind of thing. I don't
know the best way, but Im reminded about work, where we use Visual Basic
and program everything on classes. To be frank, it seems a little
cumbersome and a little longwinded, but, seems nice to maintain everything.

What they have is say a Customer and a Customers class, and the
Customers class is a collection of Customer classes. It's dog slow,
seems to be unnecessarily complicated, not easily portable, but, it
seems to be quite easy to maintain.




What are peoples opinions on this? I think I've sort of got it going
with the script below but Im unsure whether Im just being stupid.

Imagine in the Actors below, that the data is coming from a table. bear
in mind also that an Actor could have a reference to a film... for example.

I'd just like to try to understand the best way to necessarily use them.

Cheers
Simon


<?php

class Actor {
var $Character;
var $ActorName;

function Character($MyReference) {
$this->Character=$MyReference;
}
function ActorN($MyReference) {
$this->ActorName=$MyReference;
}
}

class Actors {
var $ActorCount;
var $LocalActors;

function Load() {

$ItemLoad = 0;
$this->LocalActors[0] = new Actor();
$this->LocalActors[0]->Character = "Willy Wonka";
$this->LocalActors[0]->ActorName = "Johnny Depp";

$this->LocalActors[1] = new Actor();
$this->LocalActors[1]->Character = "Billy Madison";
$this->LocalActors[1]->ActorName = "Adam Sandler";

$this->LocalActors[2] = new Actor();
$this->LocalActors[2]->Character = "Herman Munster";
$this->LocalActors[2]->ActorName = "Fred Gwynne";

$this->ActorCount=3;
}

function Item($WhichItem) {
$ActorItem = new Actor();
$ActorItem = $this->LocalActors[$WhichItem];
return $ActorItem;
}
}

$DisplayActors = new Actors();
$DisplayActors->Load();

$DisplayActor = new Actor();
$DisplayActor = $DisplayActors->Item(1);
$ActorName = $DisplayActor->ActorName;

echo "Actor Name Is $ActorName\n<P>";

$LoopActors=$DisplayActors->LocalActors;

foreach ($LoopActors as $DisplayActor) {
$ActorName = $DisplayActor->ActorName;
$CharacterName = $DisplayActor->Character;
echo "\nActor $ActorName \n Character $CharacterName\n\n<P>";
}

?>

[Back to original 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

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