5 PHP Classes You Can’t Code Without

Posted by hts | February 21, 2008 .

You probably know the old saying: “There’s no need to reinvent the wheel”, and probably you know the meaning too.
Also, as you can say from the “Tips of the Day” series on my blog, which present you quick short tips to improve PHP applications, I am an adept of clean PHP code, optimized and non-repetitive.
This […]

Unset variables after you finished using them [TotD]

Posted by hts | February 10, 2008 .

As I’ve said before, it is good practice to close mysql connections after you have finished working with them.
The same idea applies to variables, especially large arrays holding user data for example. After you used a certain variable and you are sure you don’t need it anymore in your script, simply destroy it to free […]

Do Not Overuse OOP [TotD]

Posted by hts | February 9, 2008 .

In an attempt to make every piece of code reusable and nicely encapsulated in a function / class, you might in fact slow down the execution of a script. Each method and object call consumes memory - a lot. Basically think of what code you will actually reuse later in your application / in other […]

Use PHP built-in functions for strings instead of regex [TotD]

Posted by hts | February 8, 2008 .

PHP has quite a lot of build-in, bundled functions that make your life easier - if used, of course :)
Anyway, since regex is quite a pain in the back for lots of programmers, here’s a good advice: use string-related functions to achieve what you need.
Here are some useful ones:
strncasecmp: Binary safe case-insensitive string comparison of […]

Use full paths in includes and requires [TotD]

Posted by hts | January 16, 2008 .

Problem
If you specify relative paths when you include a file, then you are wasting precious time. Doing so makes PHP resolve the OS path - that is, find the file, which is located relative to the file which requests it. This takes some time and slows down (well, not drastically, but if every bit matters, […]

Make Good Use of Predefined Functions [TotD]

Posted by hts | January 10, 2008 .

Some 1 and a half year ago, when I was a beginner with PHP (not that now I am a professional or something, but still - I’ve improved a lot :) ), I know only few of the useful predefined functions available in php and I used to build my own snippets/functions to accomplish what […]

Always define a local variable [TotD]

Posted by hts | January 7, 2008 .

Pursuing to achieve the name of “the easiest to learn and use programming language”, PHP indeed makes your life easier by doing some thing for you. For example, you do not have to declare / define each variable you’ll use in your script - PHP creates them on-the-fly. While this speeds up the development […]

Echo Is Faster Than Print [TotD]

Posted by hts | January 4, 2008 .

Here’s a quick one: use echo when you output content, since it is faster that print.
Why is that? print() is a function, in fact and therefore it takes more time to process it.
So unless you have to output formatted content (in which case you’d use sprintf(), for example), just use echo. It is faster […]

Cache the Output of Your PHP scripts [TotD]

Posted by hts | January 3, 2008 .

This one’s a no-brainer. It is obvious that every time you run a php script, the interpreter has to compile it, then spit out the html output and deliver it to the requester. If you cache the html files and serve them directly, without recompiling them every time a visitor requests them, you`ll improve the […]

Close your database connections when you’re done with them [TotD]

Posted by hts | January 1, 2008 .

You’re most likely using PHP in conjunction with a DBMS (database management system) - let’s say, MySQL.
If you’re like I used to be some time ago, you most likely forget to close the database connection you’ve opened some hundred lines above in your script.
Well, I’ve learned my lesson, so to say…and now I always close […]

Next Page »