Sideskipping PHP’s Late Static Binding until 5.3

Posted: June 30th, 2009 | Author: | Filed under: PHP | Comments Off on Sideskipping PHP’s Late Static Binding until 5.3

bindingThose of you who have experience with mixing inheritance and static members have undoubtedly run into problems regarding late static binding. When some parent class higher up in the inheritance tree has static members (methods or attibutes), getting these to work with child-classes is impossible, e.g.:

class A {
    private static $sValue = 'show from class A';
    public static function show(){
        echo self::$sValue;
    }
}
class B extends A {
    private static $sValue = 'show from class B';
}
B::show(); // echos "show from class A", not "show from class B"

This behaviour is noted as “bug” and will be changed in version 5.3.
Read the rest of this entry »


MySQL and Integers

Posted: June 26th, 2009 | Author: | Filed under: MySQL | Tags: | Comments Off on MySQL and Integers

Also tired of always looking up the minimum and/or maximum value of a MySQL integer field? For once and for all a cheatsheet:

Field type Bytes Attribute Min. value Max. value
TINYINT 1 -128 (-2^7) 127 (2^7 – 1)
TINYINT 1 UNSIGNED 0 255 (2^8 – 1)
SMALLINT 2 -32768 (-2^15) 32767 (2^15 – 1)
SMALLINT 2 UNSIGNED 0 65535 (2^16 – 1)
MEDIUMINT 3 -8388608 (-2^23) 8388607 (2^23 – 1)
MEDIUMINT 3 UNSIGNED 0 16777215 (2^24 – 1)
INT 4 -2147483648 (-2^31) 2147483647 (2^31 – 1)
INT 4 UNSIGNED 0 4294967295 (2^32 – 1)
BIGINT 8 -9223372036854775808 (-2^63) 9223372036854775807 (2^63 – 1)
BIGINT 8 UNSIGNED 0 18446744073709551615 (2^64 – 1)

HTTP_REFERER in PHP

Posted: June 23rd, 2009 | Author: | Filed under: (X)HTML, JS, PHP | Tags: , , , | Comments Off on HTTP_REFERER in PHP

linkingThis morning I added some new features to a webapplication we are developing. They worked fine in Firefox, so I opened Internet Explorer to see if everything worked in there too. Of course it didn’t…

In webapplications you may need to know which webpage requested the current one. PHP offers an easy way to find the URL of that page: the predefined server variable $_SERVER[‘HTTP_REFERER’]. Unfortunately this variable was not set in IE. So where did it go?

Read the rest of this entry »


Searchresults with misspelled Names

Posted: June 23rd, 2009 | Author: | Filed under: PHP | Comments Off on Searchresults with misspelled Names

search resultsOften, we like to present our users with the best care possible. Unfortunately, when these users fill in the forms in applications, they tend to make type-o’s. This leaves us to correct them and “interpret” what our dear users meant. Obviously, in the interest of time (but more importantly: work), this task should be automated. As I sometimes think it is really difficult to interpret what other people mean, so may computers. This article is about correcting type-o’s in city names.

Read the rest of this entry »


DB-id’s to “readable” URLs (as in tinyurl, youtube)

Posted: June 18th, 2009 | Author: | Filed under: PHP | Comments Off on DB-id’s to “readable” URLs (as in tinyurl, youtube)

eyetestTiny urls come in handy in many different occations, such as twitter, chat messages and emails. For example, sharing this article with your friends could mean sending them the url http://nostylesheets.com/2009/06/17/db-ids-to-readable-urls-as-in-tinyurl-youtube, which is long. This length could be a problem, e.g. when the link is split over multiple lines in an email: the mail client may not recognize the continued link on the next line. A tiny url can be a solution to this: http://bit.ly/dirNA links to the same article and is much shorter. Several online services are available online, such as bit.ly or tinyurl.com.
Read the rest of this entry »