mongodb/mongo-php-driver — pull request #577 by jmikola (2014-01-31 21:53:51+00:00)
Title: Fixed PHP-949: ensureIndex() creates wrong names

Supersedes #565.

Technically, the only valid index orderings are numeric negative and positive 1 (int or float) or strings (for index plugins). The server happens to accept other orderings and will create names based on those orderings, which is arguably a bug.

Looking at [BSONObj::woCompare()](https://github.com/mongodb/mongo/blob/master/src/mongo/db/jsobj.cpp) in the server source, ascending/descending is decided by whether or not the numeric ordering is zero. We'll utilize that logic to decide how to name the index (appending "-1" or "1" after the field name).

This also fixes an issue with `to_index_string()` altering its zval argument (covered in `bug00949-003.phpt`).