PHP and OOP - a few questions?

They have: 426 posts

Joined: Feb 2005

Well ive started to write some OOP and all is going well. But there are a few things im not sure about:

1) what is an interface - and am i correct in saying that you use the "implement" key word to use one.

2) Visibility: Is it necessary to always declare a function or property as public, private or protected? Also i cant seem to understand why it is useful.

3) Other OOP concepts: up to now i have heard of

Classes (objects),
methods(functions),
properties(variables),
interfaces(?),
visibility(public..etc),
contructors(method that is the first to initialize),
.........???

well what else is there or is that it? Do many of you actually use design patterns and if so what ones do you use?

He has: 1,380 posts

Joined: Feb 2002

Well... that's a very broad question.

A quick and dirty answer to all of them is to say that PHP and OOP usage are usually based on functions and structured statements.

For example:
[action A (click on something)] triggers [if statement or switch A] triggers [appropriate function]

So... how you do it is pretty varied but it's basically having a large choice of actions and associated functions, and using them correctly.

As for private, public, or protected... I've never actually used/understood them myself, so I just do a typical function call without any status declaration.

Variable usage is tricky across OOP programming in PHP so you have to be careful that if you make something global to be easily accessed, that you don't change it unless you need to. Also, make sure you pass the variables required between functions if they aren't global.

Hopefully that was a little help...

They have: 426 posts

Joined: Feb 2005

What im still confused about also with PHP is the use of creating and installing module based functionality?!

Im getting really confused with it, what does it actually mean (easy maintainability) and when a module is installed how is it installed, how do other routines access them without modifying other files directly.?

Does anyone use some of the PHP or programming patterns that are available?

As for your post above about not really using visiblity within functions and variables, it seems that im finding this object orientation PHP rather easy and i dont like things that seem easy??!! Doesnt fill me with confidence.

He has: 1,380 posts

Joined: Feb 2002

Your questions are not only all over the place, they only halfway make sense...

"Module"? What are you talking about?

The EASIEST way to do "modular" programming with PHP is create functions. Variable(s) in, Variable(s) out. Create a library of the functions you need, and then call them from your program, rather than writing the code in directly. Including this function library in all of your scripts/programs will allow you access to anything you put in there.

As for your other questions... I have no idea how to answer, because I don't even know what you're asking.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.