[ABE.pm] php 1, rjbs 0

Ricardo SIGNES perl.abe at rjbs.manxome.org
Mon Aug 11 17:52:29 PDT 2008


So, I have filed my first PHP bug of this PHP-writing campaign.

A few years ago, when JSON was starting to become really popular, someone wrote
a PHP library for dealing with JSON.  Great!  Now if your program needs to deal
with JSON, you load the extension and off you go!

JSON got more popular, though, and everybody liked the library, so PHP did what
PHP does: it made it part of core PHP.  Now you didn't need to require the
library.  You just got json_encode and json_decode for free.

There are some bugs, though.  Here's a humdinger:

  { "zero": 0e0 }

That's totally valid JSON, and the value for the "zero" property is numerically
zero.  PHP loads that as ($obj->zero = NULL).  Oops!

Well, in a library-loving culture, that's no problem.  You'd just download the
latest version of the JSON library and upgrade that.  Done!

You can't do that anymore, though, because now JSON support is in the core and
nowhere else.  You'll have to wait for the next version of PHP.  Of course,
when you upgrade *that*, who knows what other things have changed.  You're
getting one gigantic upgrade that might break other parts of your code.  "I
can't get a JSON bug fix because it would break a MySQL behavior we rely on.
No, no, they're not related."

In Perl, most libraries are not in the core.  They live on the CPAN, so you can
upgrade them in isolation.  Even those that *are* in the core are still
libraries, not part of the syntax of the language.  Many of those are *also* on
the CPAN, and there are upgraded versions distributed that won't require
upgrading Perl.  (These are called "dual-lived" modules.)

Finally, even if you had to change the behavior of a really internal bit of
Perl, you can.  You can make functions that replace built-ins, either locally
or globally.  In PHP, if you try to make a function called "json_decode," your
program fails.

Oh well.  This means my tests for the datapoint num/0e0 fail.  I think I'll
move on to the range checks.  Time to pretend PHP has closures...

-- 
rjbs


More information about the ABE-pm mailing list