version_compare

<?php
echo version_compare('anaconda', 'acromantula');
echo
version_compare('baby', 'blister');
echo
version_compare('change', 'cloister');
echo
version_compare('deviant', 'defines');
echo
version_compare('anaconda', 'blister');
echo
version_compare('baby', 'defines');
echo
version_compare('cloister', 'defines');
echo
version_compare('places', 'races');
?>

If you can tell what the output of this is going to be and why then congratulations.

<?php
echo version_compare('anaconda', 'acromantula'); // equals. Maybe first letter comparison?
echo version_compare('baby', 'blister'); // equals. Surely first letter.
echo version_compare('change', 'cloister'); // equals. Really first letter.
echo version_compare('deviant', 'defines'); // defines is lower. That's for the first letter.
echo version_compare('anaconda', 'blister'); // anaconda is lower. Again first letter?
echo version_compare('baby', 'defines'); // defines is lower. HUH?
echo version_compare('cloister', 'defines'); // equals. Really????
echo version_compare('places', 'races'); // races is lower. What's going on...?
?>

The handbook says dev < alpha = a < beta = b < RC < pl, but there is an oddity (bug?) in the implementation which causes version_compare to use these as prefixes. If we add that any string that does not start with any of the strings listed will be equal and below dev (remember, dev prefix!) then suddenly all is understandable (even if it does not make sense). See, eveyrthing beginning with a or b will be alpha or beta but "defines" will be a random string while "deviant" will be equal to "dev"... Same with "places" which is the highest, "pl", but races is a random string which is the lowest.

Edit: I need to answer some of the comments already given. This is not documented anywhere, although I will try to write it up, so RTFM won't help you. The only place to find information about this is the source code of PHP. Second, it might look weird to use version_compare on arbitrary strings but are you sure you want 2.3-gamma1 and 2.3-unstable1 to be equal?