[wp-hackers] PHP 5 any time soon?

Andrew Nacin wp at andrewnacin.com
Mon Jan 25 16:09:14 UTC 2010


>
> What about JSON/XML (i.e., libxml2) processing? Surely those would have
> some performance and maintenance benefits compared to pure-PHP solutions.
> Are those available via PECL for PHP4? I don't know much about WP internals,
> so perhaps they are already being used when available.


As two examples in how WP 2.9 handles JSON and XML:

1. For PHP < 5.2, json_decode() and json_encode() fall back to the PEAR
Services_Json class, which is bundled with WP (included only when needed).

2. In the case of oEmbed, the JSON format is strongly preferred, and if we
end up with XML on PHP 4 and don't have libxml, we don't bother with a
fallback and return false.

Instead of simply breaking PHP 4 compatibility, the idea is to use PHP
5-only features as a form of progressive enhancement. Over time, more and
more features in WP will require PHP 5 when no PHP 4 alternative is
available or if PHP4 compat just isn't worth the trouble.

I could imagine some aspects of PHP4 being confusing for somebody who may
> have started out on PHP5:

"Pass an object by reference?"

"Why is my __construct method busted?"


Developers should be coding with backwards compatibility in mind -- whether
it is PHP 5 to 4, or 5.3 to 5.1. Someone starting out on 5.2 will need to
realize that json_encode() wasn't in 5.1.

As said, there are things that trump developer convenience, but there's
nothing stopping a plugin developer from forcing a PHP 5 requirement, which
is quite easy to do. (You can even throw a fatal error and prevent the
plugin from ever being activated.) In fact, many encourage that, as a way to
ease people to (bother their hosts to transition to) PHP 5 and to reduce a
burden on the developer.


More information about the wp-hackers mailing list