I’m working on adding controls support to php-ldap, so far sending controls to the server works fine.
I would now like to be able to get the controls returned by the server.
This can easily be done when methods are returning the result object, like ldap_search does, in which case calling ldap_parse_result on the result object gives access to the controls.
But for all methods returning a boolean, I need to add some way to get the result object back.
These methods are: ldap_bind, ldap_sasl_bind, ldap_add, ldap_mod_replace, ldap_modify (which actually is an alias on ldap_mod_replace), ldap_mod_add, ldap_mod_del, ldap_delete, ldap_modify_batch, ldap_compare and ldap_rename.
I can see 4 solutions:
- Return a result object instead of the boolean, but that would be breaking BC and would mean the caller have to call ldap_parse_result just to now if it worked, it will bloat code most likely.
- Add an optional out parameter getting filled with the result if it’s there. That’s a bit ugly and would get messy if we need to add more parameters later.
- Store the result object and add an ldap_get_result() method to get the result from the last ldap call. This is close to what is done for errors. I don’t like this very much because is means storing in memory an object without knowing if it will be used, and complex ldap calls will need one more method call.
- Creating separate methods which returns the result object. This is what was done by the controls patches outthere, and what is done in the C API as well. That would result in ldap_bind_ext, ldap_add_ext, … which people would use when they need to parse the result themselves.
So I would go toward the 4th option but I’m interested in any opinion on this, or any remarks.