You are here: Classes / Functions / Autonomy « PHP Programming Language « IT news, forums, messages
Classes / Functions / Autonomy

Posted by Simon Dean on 08/15/06 18:47

Hi,

I have a couple of questions. If you don't mind. Sorry, I do get a bit
wordy at times. First one just throws some thoughts around hoping for
answers :-)

1) Anyone got a theory on the usage of PHP Classes rather than an actual
technical guide? I've seen loads of things that show how to put together
a class, but without actually necessarily saying why you'd want to use a
class over say a separate file of functions or explaining:

Class someclass {
var $WhyUseVars;
var $Something;

function somefunction ($OrParameters) {
$this->Something = result;
return $OrReturnHere
}
}

I mean, should you pass parameters into the function, or set the
variable properties of the class? Return a value from a function, or set
another variable?

What are the advantages? Which way is correct?

I start thinking, if you start using properties to pass information in
and out, it's going to get very complicated and messy with properties
that have no real useful purpose.

But then if you have one function that relies on another function, there
is the danger of getting variables floating around from one place to the
other.

eg, I pass in a code to function1. Function1 doesn't use that code, but
passes it onto Function2 in order to perform a lookup and return
readable information to Function1.

Of course, then I come up with the thought, that I might want to use the
second function outside of the first function, but I've written the
second function in such a way that it can only be called from the first
function.

2) I like minimalism and trying to keep things simple as possible,
without having to remember that in order to use a function I need to
pass it a number of the variables from the webpage or hardcoded in my
config.php file. ie, I want to give a function a certain amount of
autonomy - if it wants a constant in my file, it should get it itself.
Of course when I first started out, I was using globals.

Anything better?

Maybe I could just have a "SiteParameters" class, create a new instance,
and get the information that way?

Im not sure what the best way is, I know I just want to avoid needless
repetition, keep things simple, and avoid the situation where Im passing
the same information in chained function calls.

Cheers
simon

 

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

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