PHP Shorthand If Notation or the Ternary Operator

Why should I care about PHP Shorthand If Notation or the Ternary Operator

Programming would be a bit useless without being able to evaluate conditions using if/end and switch statements. If/Else statements is obviously a great tool, but they aren’t optimal (or necessary) in all situations. And so I introduce you to … PHP Shorthand If Notation or the Ternary Operator.

Ternary operator takes the form “(condition) ? (true return value) : (false return value)” to shorten your if/else structures.
(more…)

Continue ReadingPHP Shorthand If Notation or the Ternary Operator

Hints to help optimise the performance of a PHP website (LAMP)

Over time, the websites I have been involved in have became more and more complex (and indeed carry more and more traffic).

And so the ever increasing need to optimise and increase the performance of your website (or web-application) becomes more crucial.

As you will appreciate this is a HUGE subject, so I aim to simply put you on the path to devising a better architecture and design. But I will attempt to introduce some ideas to assist…

(more…)

Continue ReadingHints to help optimise the performance of a PHP website (LAMP)

Why does php not show errors? – How to display PHP errors when display_errors is disabled

OK, a simple thing I know. But one that always occurs.

When using shared hosting (or even your own dedicated servers), those managing those servers do their utmost to make them secure. Among many things this usually includes turning off ‘display_errors’ in the php.ini file.

However, when you’re trying to develop things it is usefull to display errors and warnings, but if ‘display_errors’ is off, you will be scratching your head wondering what’s going on and whats going wrong!
(more…)

Continue ReadingWhy does php not show errors? – How to display PHP errors when display_errors is disabled

Beginning your journey in Object-Oriented Programming using PHP

Object-Orientated programming is not a new idea! It’s been around and available for a long time in many languages.

With each new version of PHP, new features appear, while existing features are improved. PHP’s object support has been hugley improved since it’s introduction in PHP3 (yes it has had it all this time!). And so with PHP’s object support maturing, the reasons developers might not take an object orientated approach are getting smaller. More recently PHP5′s take on objects is much more powerfull and usable than it ever has been for PHP users – but still not without it’s faults.

A common problem that experienced (and new) PHP developers have when embarking on their object-orientated (OOP) journey is thet they don’t know WHEN to use it properly! As with all things there is a time and place for everything.

For those who do not know about OOP I am not even going to attempt to explain what it is! But fact you have found this article means you probably do, but incase not Wikipedia has good general background info on OOP.

(more…)

Continue ReadingBeginning your journey in Object-Oriented Programming using PHP

Session Handling in PHP

Traditionally HTTP is a stateless protocol. That is it is made up of requests and responses and there is no notion of a ‘persistent connection’. This means that there is no way to have consistency or personalisation on the web since there is no way of knowing whom the request came from.

There are 2 primary methods – regardless of platform – that are used as a work-around for this.

First is a cookie. A cookie is a text file that lives on the client’s computer that store values set by your application. In general the file can only be access by the website/domain that issued it. The main problem with cookies is that they are un-trusted. A malicious user could modify the data and cause you problems!

The second – and better – solution is sessions. Similar to cookies, but they reside on the server, and cannot be directly modified by the client. When sessions are used, a cookie is still issued, but this simply holds the ‘session id’. This session id is generally sent by any request after it is created by the app including actions such as form submission. This ‘session id’ is a link to either a file or record on the server – depending how they are stored.

(more…)

Continue ReadingSession Handling in PHP

Signs of poor PHP ‘products’

If you are a professional developer (or aspiring) you will inevitably get asked to customise or even better “extend” existing wares.

If it’s a product you are familiar with great! If not I heartilly reccomend spending a little time investigating prior to accepting a job ( ultimatley if they are happy to give

access to their code, if not atleast tell you what’s been used so you cam repliocate it to play with briefly). I know this sounds like a lot of work wich ultimatley – if you

don’t accept the job – you have done for free, but it will save you masses of grief, tears and late nights if you do.

So, I have a few pointers to ‘be aware of’ while evaluating the job and to (generally) identify crappy PHP products/solutions quickly…

(more…)

Continue ReadingSigns of poor PHP ‘products’