How to make your PHP code reusable

No one likes to write similar code over and over again, it's dog work, and whenever you write code one of your aims should be to avoid any repetition. Not only does it mean you can avoid writing more code, but it'll help to make your application more efficient. PHP is well geared to enable you to do this by giving you the ability to create functions and classes, and there are a few simple things you can do to help you make your code more reusable. Don't hardcode your variable's values We've...

Read more

How to successfully use Stack Overflow

Stack Overflow (SO) - in my opinion the greatest problem and answer site there is for developers of all languages. For those new to the site, I have often noticed on occasion they appear frustrated with the users for one reason or another, and this is usually down to a lack of realisation to how the site operates and what its real purpose is. Problem solving, not code writing The first big mistakes new members sometimes make is to think that SO is a place to have code written for you. Let me...

Read more

A guide to PHP Frameworks for those new to the concept

The biggest step a PHP developer will usually take in their development will be from procedural code to object orientated (OO) code. I'm going to assume here that you understand the basics and benefits of OO development, and now want to take the next step - to a full framework. What is a framework? It is what it says on the tin: It's a framework designed to make your life easy. It should make developing new applications quick and easy compared to starting from scratch with no files in place...

Read more

My own PHP Style Guide.

Working with code that's worked on by others too can lead to a big old mess when it comes to the style of the code. In the office I work in, we pretty much all style our code differently, and we're only a very small team. I spend way too much time re-styling their code to suit my own standards (which of course annoys them, but I can't help it!). Indentation and Nesting So, what does my personal style guide look like? To begin with, lets look at indenting and nesting. My personal preference...

Read more

Are you still using PHP’s mysql_* functions? Please, switch to PDO today!

I'm a fairly active member of Stack Overflow, and it's painful to see how many questions are posted that still show code using the mysql_* functions for connecting to and querying MySQL. The most worrying part about this is the fact that this is new code being written, by newcomers and experienced developers alike. So, why am I so pained by the use of these functions? Well first, these functions are have now been officially deprecated from PHP. Since version 5.5.0 (See the GIANT red box?). That's...

Read more