Dec 18th, 2008 by admin | 4 Comments »
I’ve been coding in PHP for probably eight years and thought I knew the language pretty well. Was I surprised the other day when I came across someone else’s code and stared at it blankly, wondering why they had done what they did, and why wasn’t it generating an error. Specifically they had something like this:
echo "Your IP address is {$_SERVER['REMOTE_ADDR']}";
Why were those curly brackets in the echo statement and why wasn’t this giving me errors? I removed the curly brackets and as expected, I received syntax errors. Apparently the {} were magical. Now in my own code, I would typically write the above line like:
echo "Your IP address is " . $_SERVER['REMOTE_ADDR'];
or
echo "Your IP address is $_SERVER[REMOTE_ADDR]";
Now method one is perfectly valid code, but it’s a bit ugly having to starty and stop the string to insert a variable. Method 2 is somewhat wrong as the quotes have been removed from the server array key. According to php.net, “Always use quotes around a string literal array index. For example, $foo['bar'] is correct, while $foo[bar] is not.” But with this new, more compact method, I could make my code cleaner. I was off to learn more.
After some searching I discovered that PHP will allow you to place curly brackets around a variable in a string (either around the entire variable or with the dollar sign sticking out). “If a dollar sign ($) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name. Similarly, an array index or an object property can be parsed. With array indices, the closing square bracket (]) marks the end of the index. The same rules apply to object properties as to simple variables. ” Who knew? I must’ve missed this day during PHP 101 class. Here’s the example from the manual:
<?php
$beer = 'Heineken';
echo "$beer's taste is great"; // works; "'" is an invalid character for variable names
echo "He drank some $beers"; // won't work; 's' is a valid character for variable names but the variable is "$beer"
echo "He drank some ${beer}s"; // works
echo "He drank some {$beer}s"; // works
?>
So in a nushell, when using variables in a string you are allowed to enclose the varable in curly brackets to allow variable expansion without having to jump in and out of quotes, or drop quotes. Who doesn’t love PHP?
Tags: PHP
Posted in PHP | 4 Comments »
Dec 2nd, 2008 by admin | No Comments »
Internet Explorer 6 is the bane of a web developer’s existence. Released in 2001 (decades ago in internet time) it still composes somewhere between 20% and 30% of the browser market. While there are several other, more capable browsers out there for users to choose from, including Microsoft’s own IE7, and its successor in beta IE8, people still use IE6 at an alarming rate. Over the years Microsoft released updates and patches for IE6, yet it is still stands as one of the worst browsers to have ever existed, so why are people still using it?
“I’m used to it, so why should I change?” is just one of a variety of reasons people give for continuing to beat this dead horse. Other popular reasons IE6 users give for not updating to IE7 are because they’re prohibited from changing their system (i.e. a work pc combined with corporate sloth or ignorance), they visit a web site that (supposedly) works best in IE6, or they just don’t know any better. As designers it’s our jobs to design beautiful, accessible web sites, not worry about why our margins look weird in IE6. For years we’ve devoted countless hours of work finagling our designs and code to accommodate this scourge of a browser.
What to Do?
As a designer it’s time to stop catering to sloth and ignorance and take a stand. For years we’ve bent over backwards to try and compensate for IE6’s massive shortcoming with hacks and tricks like conditional CSS comments and browser detection so that we can deliver IE6-specific workarounds. We’ve used GIFs and JPGs instead of PNGs or used hacks to get IE6 to render them properly. This needs to stop now. By continuing along this path, we’re simply enabling people to continue to use IE6 and give them no compelling reason to upgrade or switch browsers. IE6 is Swiss cheese in terms of security, doesn’t adhere to modern CSS standards, or support PNG images just to name some of its bigger problems. From now on, don’t waste time worrying whether or not to use PNG files – use them. Don’t bother checking browser versions and providing alternate, IE6-specific code. Design once.
But what about for testing purposes?
Nope, not even for testing purposes. What are you hoping to accomplish by testing a site in IE6? If you discover a problem, why bother fixing it? Pages need only adhere to W3C standards and pass the usual array of validators. If IE6 can’t render them properly, then that’s IE6’s problem.
The Good News
The good news is that the number of people using IE6 is steadily dwindling. Firefox, Chrome, Opera, IE7 & 8 are all better browsers and are gaining market share while IE6 loses it. While it’s just a matter of time before IE6 disappears, let’s help accelerate that demise by taking a stand and turning our backs on it. Stop Supporting IE6. Now.
Posted in Rants | No Comments »
Sep 4th, 2008 by admin | No Comments »
After using Google’s new Chrome browser for a couple of days I have to say that it shows promise as being a great choice for my go to browser. With some work. Here’s a quick rundown of my initial pros and cons…
Pros:
- Fast
- Fast. I mean really fast
- Intuitive to use
- Did I mention it’s fast?
- Great new features. I love being able to tear off and rearrange tabs, searching and bookmarking are cake, and it doesn’t seem to have any obscure page rendering issues.
- Easy to use download manager
- Auto hide status bar
- Runs better than IE8 beta.
- Cool Opera-like start page
Cons:
- No home button in the toolbar
- No print preview
- No Undo Close Tab feature like Firefox has.
- No add-ons (yet). Chrome’s source code is available now so we’ll see what happens with that. Adblock is my favorite Firefox extension and if Chrome can get something similar (yes I realize Google owns Adsense) then it will be a huge plus.
- Lacks some basic customization features
I’m eager to see how the browser’s development progresses and how it impacts Firefox and IE.
Tags: Chrome, Google
Posted in Uncategorized | No Comments »