Thoughts, rants and commentary of a simple man

No whale hunting in Oklahoma

Posted on April 1st, 2009 in Cool Finds,Did you know?,Funnies | No Comments »

Ever read one of those little snippets that makes you take a second to really listen to the text of it again in your head, just to make sure your brain and eyes are communicating properly? What if you read a whole list of true facts/laws/ordinances that seemed to make no sense but are nonetheless still true facts/laws/ordinances?

The other day I was sent a link to a listing of strange facts and like a train wreck I could not look away. So rather than fight the urge to stay clear of the nonsense I dove headlong into it.

From that list, here are my top few favorites:

  • You can’t plow a cotton field with an elephant in North Carolina
    But dude, that would be the best way to do it because they animal is sooo big.
  • In Lehigh, Nebraska it’s against the law to sell donut holes
    Probably because of some high schooler’s shenanigans where someone woke up one day and found the middles of their donuts missing.
  • Every citizen of Kentucky is required by law to take a bath at least once a year
    Because once a decade is really not considerate enough.
  • It is against the law to whale hunt in Oklahoma
    Think of the whales that will be saved by this one. Whew!
  • In Breton, Alabama, there is a law on the town’s books against riding down the street in a motorboat
    Again, darn high schoolers. And I had a big time summer trip planned in Breton already. Complete with the motorboat. There goes that one.

In honor of the beginning of April… HAPPY APRIL FOOL’S DAY! 🙂

Back to top

Did you know PHP function names are case insensitive?

Posted on March 6th, 2009 in Did you know?,PHP | 2 Comments »

I colleague of mine recently asked me a question over IM that went something like this:

Do you know if function names in PHP are case sensitive?

My reply was simple: no, they are not. I know this because about a year ago I ran into this same exact situation and was met with an unruly error message about trying to redefine a defined function. The scenario was simple… I tried to change case on a PHP native function thinking that since every other part of PHP is case sensitive that obviously functions names would be, too. Wrong-o.

What this means is that if you wanted to, you could use all UPPER CASE LETTERS when calling PHP functions, like:

<?php
IF (ISSET($somevar)) {
  HEADER('Location: http://www.robert-gonzalez.com');
  DIE();
}
?>

It looks ugly, but is perfectly valid. Of course, since case means nothing to PHP when it comes to function names, you could also play around a little and have some fun with it:

<?php
IF (isSet($somevar)) {
  unSet($somevar);
  Var_Dump($GLOBALS);
}
?>

I know, it seems odd behavior to me, too. But that is just the way it is. Wanna know something else?

I found out a little more than I had bargained for when researching case sensitivity of function names. Class/Interface names are also not case sensitive. So if you have a class named MyClass and you instantiated it with new myclass it would be perfectly valid. Even instance comparison works against it, so you would be able to do something like if ($c instanceof myclass) and it would be valid:

<?php
class CaseTest {
  public static function lowerName() {
    return 'this is a lower case string';
  }
 
  public static function upperName() {
    return 'this is an upper case string';
  }
}
 
$c = new CASETEST;
$is = 'cASeTesT';
if ($c instanceof $is) {
  echo '$c is an instance of ' . $is . ': see? -> ' . get_class($c);  
}
?>

You wanna know more still yet? You guessed it… method names are not case sensitive either. That means that you could get away with a lot of case insensitivity, even something like:

<?php
class CaseTest {
  public static function lowerName() {
    return 'this is a lower case string';
  }
 
  public static function upperName() {
    return 'this is an upper case string';
  }
}
 
function runtests() {
  echo casetest::lowername();
  echo casetest::UPPERname();
  echo casetest::UPPERNAME();
}
 
RUNTESTS();
?>

This seems totally counterintuitive for a case-sensitive language like PHP. And in fact I have always observed case sensitivity when coding just because it makes sense to me to do so. But there have been times when I didn’t know the case used for a function or method and used it all lower case just because I knew it would work.

Anyway, for any new developers out there, or even for seasoned developers that have never ran into this, now you know. In almost everything in PHP case matters. In function names, class names and method names, however, that is just not the case.

Back to top