Mon, 28 Mar 2016

PHP Compares Things Weirdly

— SjG @ 10:36 am

This is a known .. uh … situation, but it bit me today.

So, consider the following:
$ php --version
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
$ php -a
Interactive shell
php > $v1 = '479014103257633139480';
php > $v2 = '479014103257633139481';
php > echo ($v1==$v2?'Equal':'Not Equal');
Not Equal

Seems sane, yes? Reasonable. Kind of what you expect.

But then, consider this:

$ php --version
PHP 5.3.3 (cli) (built: Feb 9 2016 10:36:17)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
$ php -a
Interactive shell
php > $v1 = '479014103257633139480';
php > $v2 = '479014103257633139481';
php > echo ($v1==$v2?'Equal':'Not Equal');

Yeah. Let that sink in for a moment.

Some versions of PHP (before 5.4.mumble) will preƫmptively convert strings to numbers before comparing them (if they contain only digits). But if the number is large enough, you may lose the precision to compare them correctly.

Wow. I mean, just … well… I dunno.

For what it’s worth, strcmp will do the right thing regardless of PHP version. But seriously. I mean. Why do I use this turdburger of a language?

Sat, 19 Mar 2016

Another Dinner Party

— SjG @ 4:43 pm

Back in August, I held a fantasy dinner party. At the time, I intended to do that monthly. How weak are intentions šŸ™

Well, here’s another one. This month, as a theme, it will be all people known by their nicknames.

If you were throwing a dinner party, and had a table for eight, a fantastic chef, an unlimited travel budget, and were able to invite seven guests1, who would you invite?

While picking a good table is an impossible challenge, here’s what my second table would look like:

Who is coming to your dinner party?

1 I’m making the assumption that the invitation would be so compelling that the guests would all attend. And I’m further limiting this thought experiment to living people.

Filed in:

Kwan Yin Stereogif

— SjG @ 9:08 am

Equinox in the Garden.


Stereo separation’s a little too wide on this experiment. I think it might be time to fabricate a precise positioning rig for my tripod… another project on the list.