Posts Tagged ‘web development’

Type Hinting in PHP

Saturday, September 5th, 2009

PHP 5 introduces Type Hinting. But it does so in the usual PHP way: It’s neither fish nor fowl. You’ll be exited at first when you discover the new feature. And then you’ll be disappointed. Because things do not work like you’d expect. Suppose you do something like this:

  1. <?php
  2.  
  3. function foo ( string $bar) {
  4. echo $bar;
  5. }
  6. foo ('Hello World!');
  7.  
  8. ?>

What happens, when you execute the above code? You will get a rather cryptic error message:

  1. Catchable fatal error: Argument 1 passed to foo() must be an instance of string, string given.

So the method expected a string as the first parameter and you passed a string to it, but PHP chose to throw up regardless. Great, isn’t it? Of course, the reason for this is right at the very bottom of the PHP documentation on Type Hinting. All the way down the page below a number of examples:

Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn’t supported.

Doh!

Where have all the records gone?

Sunday, August 16th, 2009

I’m currently working on a web application and I set up a development version of this application on my local box. For my convenience I set up a number of unit tests to ensure that I do not accidentally break stuff when implementing new features. A number of unit tests that involved DNS failed repeatedly with a time-out. For various different reasons I’m using a router provided by my telco. During my investigation of the matter, I found out that the internal DNS server of the router did only answer requests for A records. Requests for any other record types timed out. I wonder why they do this. The only reason I can think of is that it’s part of my ISPs fight against malware installed on their customers Windows boxes, so this is not exactly evil. On the other hand, it is not very nice of them, because I’m sure that it cost me a few hours to debug problems that resulted out of this. I think that I’ll call them and at least tell them that there are customers out there who really need the real, full, unfiltered DNS service to get their work done.

Quick and dirty: Disable web cache in Firefox 3.5 (Shiretoko)

Thursday, April 16th, 2009

It’s sometimes necessary to disable your web browser’s cache, especially, if you’re doing web development. If you’re using a legacy Firefox build (e.g. Firefox prior to 3.5), you could use the excellent Web Developer Toolbar by Chris Pederik to do this (on the Disable menu, select Disable caching). But if you’re living on the cutting edge of things and use a nightly build or a beta build of the current Firefox 3.5 (code name: Shiretoko) like I do, you can’t use the extension, because it is not compatible with nightly builds or recent beta builds (as of this writing).

Thus, a quick and dirty approach: First, type about:config into the URL bar. You’ll see a warning, that advises you to be careful. Be careful. After carefully dismissing the warning, enter network.http.use-cache into the filter bar. You should now see the preference of the same name. Double click on the value to change its value. If the value is set to false, the cache is disabled. If the value is set to true, which is the default, the cache is enabled. Despite the name, caching of sites using the https protocol will be disabled, too. And don’t forget to re-enable the cache after you’re done with whatever you wanted to do.