Best PHP Practices

One of the things I hear from people and my friends is questions about the best way to work with PHP. They always want to know how to get started on a project, what software to use, how to plan it successfully, and so on. In this article I plan on revealing the “magical secrets” about how I do my PHP programming so quickly with so few bugs.

What’s the Big Deal?

One night while watching my various cartoons on Adult Swim I got a call from a friend begging me to lend him a hand and tell him how I program PHP so fast and accurately. He was rather disappointed when I told him that a book or a website isn’t what made my skills so impressive to him. After I told him what I did, it improved his PHP abilities tenfold. So I thought it would be useful to everyone to know what I consider to be the best practices while developing PHP. There are many PHP editors out there; trust me I’ve used just about all of them, from full blown “what you see is what you get” editors, all the way to those that are a Windows notepad clone. So I plan on filtering out the best from the worst. On top of that I’m going to be telling you all about the best programs for working with HTML and MySQL, and I’m also going to be talking about how to plan your project, where to get started, and where to go from there. I’m also going to try to explain how to document your code, and how to format your code so that you minimize the amount of time you confuse yourself (admit it your own code has confused you before… at least once).

{mospagebreak title=It’s like Typing, only with a Pencil}

If you’ve read any of my other articles, you’ll know what’s coming at this point. That’s right, grab your paper and pencil. It’s time to be a little old school. I’ve always found that if I draw out my plan on paper that it’s easier to code because I know what goes where how it all links together and what type of structure I’m working with. Also, it’s nice once you’ve been working on your project for some length of time to be able to look back on what you’ve already done so that you can easily remember things about your project that you may have forgotten.

Writing down things like declared class names, global variables, function names, and so on really can give you an edge if you get right down to it. Let’s say you have two classes, one named load_interface and one named load_ini, or something, then let’s say you’re one of those type of people who will declare a class with a two-letter variable (and I know there are those of you who do it). Well, if you made load_interface three weeks earlier in the same project, and you didn’t use it for all that much, are you really going to remember that you’ve used the $li variable already.. really?

Some people may not. Or, let’s say that you start a project and then you get someone else to help you out after about a week or two. Wouldn’t it be useful to them to know what’s already been used? And would it not help speed up the time it takes them to actually get into the project to start programming?

That just goes to show you — “paper isn’t just for breakfast anymore” –well, it never was, but I’m just saying there’s more use for paper than letting it jam your printer.

{mospagebreak title=What You See is… Well, You Know}

I regret to tell you that what you see isn’t always what you get. There are many different HTML editing programs out there; the top two are Macromedia Dreamweaver and Adobe GoLive.

Macromedia Dreamweaver is the choice of most people, mostly because of the dynamic language capabilities. However, as a true PHP programmer that should be no concern of yours, as true PHP programmers do all their PHP by hand instead of letting a program generate it for them. So basically it comes down to what you prefer. Until you actually take a look at both programs.

Personally after much time, use, and thought, I’ve found that Adobe GoLive would be the best choice for a PHP programmer. Due to the fact that it has a more familiar interface for those used to using Photoshop. I’ve also found that it has real time WYSIWYG capabilities while with Dreamweaver, you have to refresh after you make a change, and not to mention, it has real time rendering that will show you the HTML in small emulators of each browser.

However, like I said, it’s really up to you and your personal preference as to which HTML editor you use.

{mospagebreak title=Get your Hands off MySQL!}

Well, there are many, many MySQL front ends out there. I’ve used a bunch of them. The one I like the most is called MySQL front. It’s not very expensive at all and it’s really a powerhouse of a MySQL GUI. However there are a lot of free ones out there. MySQL cc is a free one that is offered on MySQL’s website.

It’s really important to have a front end for MySQL, because working with MySQL at the command line interface can take up a lot of time. One of the best things about using a front end is that some of them can generate your SQL statements for you. In fact there’s another one out there named MyDB Studio, which is just that. It’s a query generator. It’s the best I’ve seen so far, and nevertheless, its main focus is generating queries for PHP scripts. There are a few other generators like EMS MySQL Manager, but it isn’t really geared toward PHP specifically like MyDB studio is, not to mention it may have a lot of nice features, but they don’t really make EMS MySQL Manager as useful as MyDB Studio is. MyDB Studio will generate select, insert, update, and delete statements for you then even generate PHP that connects to the database and runs the query.

On the other hand, sometimes I find that with smaller, less complex queries it’s easier to just code them by hand. Also it’s really nice to have your own little SQL class in another PHP document that you can just include into your project, so that you can just call a class set some parameters and, BOOM, instant SQL connection. I’ve even seen a class available in forums that will build queries for you all you have to so is send the parameters to it.

{mospagebreak title=PHP Time, YAA!}

Here’s a really good question: What PHP editor should I use? Personally I use Zend Studio, which can get pretty pricey if you don’t plan on making money from your coding. But it’s by far the best PHP editor I’ve ever used. It has a built-in debugger, or you can install the one that’s made for your server. It will also profile your project so that you know what is taking the longest to parse. But that’s not what makes it so nice of an editor. The fact that it has true PHP auto complete is a big thing to me. It has pretty much all the built-in functions in the auto complete, and it also adds in the variables, functions, and classes that you make into the auto complete features. I’d say overall my programming speed has increased by 75% since I’ve been using Zend Studio. After all, who would make a better editor than the company that basically creates the language?

On the other hand, if your wallet is as empty as a LAN party with no computers, you can always go for Maguma Studio Free. It’s a pretty good editor for free. It has great integration with the PHP documentation and a decent auto complete feature.

And for the hard core “I am PHP” type of programmer, you can always go with Arisesoft Winsyntax, which weighs in as Notepad with PHP syntax highlighting.

That’s really about it for PHP editors, although there are hundreds of them out there. Those three are probably the best in their categories.

{mospagebreak title=Where Do I Start?}

I’d bet a piece of paper and a common writing utensil could help you out here. The most important thing to think isn’t, “where should I start”, but “where do I want to start?” I always start with the graphic layout of a site before I do any coding. This why I know what my limits are when I’m trying to code something. I know what kind of output I can work with and simple things like that. Then I figure out what the main focus to the project itself is, and I go from there.

Usually it’s best to get the most important part working first so that you have something to show, and not to mention you can get input from other people on what they think of it, before you go putting a bunch of time into the things that aren’t as important. On most of my projects, I always start with the database connection first, then I move on from there, usually to the authentication, then the layout and interface. Finally I code any content management systems I may have, followed up by the smaller and more tedious parts; they usually include things like allowing the users to have an avatar, and things like that.

Doing it this way is usually the best way because if a project gets abandoned, you’ve probably now got something cool that you can add to your library of scripts to help you build your scary PHP empire later down the road.

I’ve also found that if you do in fact code the big parts first, you’ll see that you’ll spend less time going back to update finished code to work with the new things you have. And there’s less of a chance of the project being abandoned due to the lack of visual progress. Not to mention you get one of those really cool feelings of accomplishment half way through a project when you finish the important things.

Another reason I like to code the bigger more important parts first is because you’ll get stuck on something at one point, which will make you search out an answer to your problem. You’ll end up learning a lot of new things about PHP that you probably didn’t know, but you’ll remember them because they’re so cool that you’ll want to use some of the things you find in the smaller parts of the project for added functionality. I mean really useful things too, like the mysql_fetch_object() function. Do you know what that does? If you don’t, I bet you’ll say “WOW that’s so cool and useful” as soon as you look at the PHP documentation to find out what it is.

{mospagebreak title=Loose Ends}

No matter what level of programmer you are, a newbie just starting, or a war-battered veteran of php3, the most useful thing you can have at your side is a downloaded copy of the PHP documentation. I keep it on my quicklauch bar, if that means anything about how useful it is. No joke, it’s right there with my browser, and that’s all that’s on there. I’ll show you a screenshot if you don’t believe me. Even though I’ve been programming PHP for about five or six years now, I don’t know how I’d get by without my trusty CHM PHP manual.

And last but not least. Bigger isn’t always better. Stick close to what you planned on making. Don’t go overboard with useless features that usually slow down parse time and development time for something that one percent of your users will use. Get your project done and working then implement those things later. After all, nothing really shows what is needed in a project than the use of it.

And always remember, when a person tells you there’s a bug in your script, happily inform them that “my code doesn’t contain bugs, it just randomly generates new features” then quickly fix the problem before they go back to see if it actually is some kind of odd feature. Good luck, and please, never use Microsoft Word to generate HTML.

[gp-comments width="770" linklove="off" ]

chat sex hikayeleri Ensest hikaye