0

hi

Ive realised that I have some way to go before I can call myself an accomplished php developer. I want to transfer my skill set into legit object orientated design, and also to learn best practice for designing php apps for the web... to the extent that I need advice on how to organise each script on my server etc... so Im looking for a comprehensive book :)... I bought PHP5 Advanced (quick Pro Guide) because it had three chapters on OOP, including 'Real World OOP', but it turned out to be only vaguely useful - Larry Ullman actually says that you needn't consider OOP as a PHP programmer, though it is an option...

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by phpbeginners
1

Here's some pro-tips from me

don't be clever - other coders will be looking at your code. It's much better to use simple approaches than clever ones, most of the time. now if you need to do things to speed up your page, or fit a constraint, then by all means be clever.

use a MVC approach. Have a section of your code get the data. then a display section use the data that was previously retrieved. This makes the code more reusable and easier to understand.

Don't do inline coding. For much the same reason we use .css files and don't do inline css, don't mix HTML and PHP. This is tied to MVC principles. The controller part can be a framework like Prado

when doing a conditional with a literal, put the literal first. ie use if ('apple == $fruit) over if($fruit == 'apple') because if you forget 2 = signs, it will assign the value, and putting the literal first will prevent this from happening.

OO - it's really not NEEDED but I find it does make the code easier to understand, use, and keep organized if you use it. I always opt for using OO.

use descriptive variable names. $i, $x, $id = bad. $nameCount, $bookID, convertStringArrayToCamelCase() are good names.

If you use good names, you won't need to comment as much. But remember, code describes what to do, comments describe why it's happening.

be consistent with naming techniques. database variables, classes/object, variable names, etc should use a consistent technique when it comes to naming. lower case? camel case? upper? etc.

0
Some Folder Structures:

root directory |
                      | downloads
                      | ext
                      | images
                      | includes --> includes file
                                      | body
                                      | boxes
                                      | classes
                                      | functions
                                      | java or javascript

                       | languages
                       | local
                       | modules
                       | template

index.php - on root

you can put all your OOP in "classes";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.