Thursday, 30. August 2007, 05:16:17
PHP, design patterns, programming
Globals are evil - do not use them. Quoting
Martin Fowler,
remember that any global data is always guilty until proven innocent.
What is a global? A global is a variable that is accessible from anywhere in an application. For example, in PHP declaring any variable outside a function/class method will make it global.
But what about when I want to have some data globally available in my application?
One useful solution is to use the singleton pattern to create a storage class or something like that. We'll look at that later in this post.
Read more...
Wednesday, 29. August 2007, 04:53:17
PHP, python
Sometimes you might need to communicate with some other process when working with PHP. Say you have a custom server application running on your server and you need to send it some data when a user accesses your website.
There are a few things you could do to achieve this:
- Create a file and poll it with your server for new data
- Use a database and poll it from your server for new rows
- Use a named pipe
As you can see from the list, all other options except named pipes require you to perform polling. With files you'd need to open and reread the file and with the database you'd need to perform queries to check it for new rows. With a named pipe, the application can just open it and wait for data.
Read more...
Saturday, 25. August 2007, 19:25:47
web, CSS
There are some useful tricks you can use in CSS to position content.
Some people frown upon absolute positioning, but that is because they don't know how useful it is if used properly. Relative positioning has some uses, too.
Here's some examples of using CSS
position: absolute and
position: relative.
Read more...
Wednesday, 22. August 2007, 15:39:35
PHP
We've all had problems with our PHP scripts. PHP can be a pain to debug at times and especially on servers that haven't been configured with PHP development in mind.
PHP doesn't always show errors, which makes finding the cause of an error problematic if you don't know what to do. PHP's functions for displaying variable info and debug info aren't very good etc.
Let's look at some good ways to make PHP help you find the problems, including how to configure it to display all errors and a free PHP extension called Xdebug that is a tremendous help in debugging.
Read more...
Saturday, 18. August 2007, 07:43:57
programming
Do you use variable names like $a, $b or maybe $foo or $bar in your code?
Stop using them, it's bad practice.
I've used similar variable names such as those for a long time myself, but I've been moving away from them for a while now.
But why is it bad?
Read more...
Sunday, 12. August 2007, 09:33:29
PHP
As I've been working as a freelance PHP programmer for a while now, I've already sometimes encountered clients without PHP5 support on their servers.
This sometimes causes small problems when I've used PHP5 syntax or such.
So it would be useful to have both PHP4 and PHP5 on your server so you can switch PHP4 when needed.
The solution is to run PHP4 as a CGI-script. Later in this post, I'll tell you how to enable PHP4 as a CGI script for Debian.
Read more...
Friday, 10. August 2007, 15:04:57
design patterns, PHP, source code
In my
post about the problems in Zend Framework implementation of the MVC pattern I briefly mentioned the factory design pattern and that it could be used to create a view factory.
In this post I'll explain the concept of the factory a bit further and provide an example view factory implementation for you. We also brush the singleton pattern a bit.
Read more...
Wednesday, 8. August 2007, 20:37:24
PHP, programming, web applications
Today I did some research and looked up how you do AJAX in ASP.NET 2.0.
Microsoft has released an AJAX extension for ASP.NET 2.0 which makes doing AJAX enabled pages very very easy. Let's compare the way you'd do AJAX in PHP to the way you use in ASP.NET.
Read more...
Monday, 6. August 2007, 20:20:00
PHP
If you consider how the MVC pattern works in the Zend Framework, it first seems just fine. And yes, it is actually very good, but there's one problem:
It isn't designed to let you access your Models from the ViewsRead more...