Hey Côme, hey Andreas.

Am 03.07.17 um 17:04 schrieb Andreas Treichel:
> Hello,
> 
> please change the signature form
> 
> bool ldap_exop_whoami(resource $link, string &$result)
> 
> to
> 
> string ldap_whoami(resource $link);
> 
> i dont see the benefit to return a single value with a reference.
> 
> Without a reference the function can used as an argument:
> doSomethingWithTheUserName(ldap_whoami($link));
> 
> 
> With a reference a variable is required:
> ldap_whoami($link, $username);
> doSomethingWithTheUserName($username);
> 
> 
> same with the return statement of a method:
> 
> class MyLdap
> {
>     public function getCurrentUser(): string
>     {
>         return ldap_whoami($this->link);
>     }
> }
> 
> class MyLdap
> {
>     function getCurrentUser(): string
>     {
>         ldap_whoami($this->link, $username);
>         return $username;
>     }
> }

After thinking a while about this I think it would be a good idea to
alter the signature of the functions and return a value or FALSE instead
of a boolean value.

In my eyes the code and the extension would benefit in a few ways:

* It would allow us to slowly get rid of pass-by-reference variables
* It would make it easier for users to get a value
* It would allow us to shift to use Exceptions instead of errors more easily

For methods that could return more than one value we could return an
array or an object.

There are currently both ways in the code but from the discussions I've
had so far I've learned that removing the references (and getting rid of
the resources) would be a plus.

From what I've seen in the code at least removing the pass-by-reference
should be possible without too much changes.

So the signatures would look like this:

string|FALSE ldap_exop_whoami(resource $link) - The returned string is
the DN of the currently bound user.

string|FALSE ldap_exop_passwd(resource $link [, string $user [, string
$oldPassword [, string $newPassword]]] - The returned string is the new
password of the user. Either the given newPassword or a newly generated one.

Both would return FALSE on an error (or throw an Exception) so one can
use them like this

if (false === ($password = ldap_exop_passwd($link))) {
    // something went wrong
} else {
    echo $password;
}

Or is that complete and utter nonsense?



Cheers

Andreas

-- 
                                                              ,,,
                                                             (o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl                                                       |
| mailto:andr...@heigl.org                  N 50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org                       http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca                                               |
+---------------------------------------------------------------------+

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to