Skip to content

ext/ldap parameter fixes #6153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed

ext/ldap parameter fixes #6153

wants to merge 16 commits into from

Conversation

MCMic
Copy link
Contributor

@MCMic MCMic commented Sep 17, 2020

This fixes inconsistencies between code, documentation and stub to better support NULL as an equivalent of not passing a parameter.

It also renames parameters to be consistent and concise.

@@ -4,177 +4,177 @@

#ifdef HAVE_ORALDAP
/** @return resource|false */
function ldap_connect(string $hostname = UNKNOWN, int $port = 389, string $wallet = UNKNOWN, string $wallet_passwd = UNKNOWN, int $authmode = GSLC_SSL_NO_AUTH) {}
function ldap_connect(string $uri = null, int $port = 389, string $wallet = UNKNOWN, string $wallet_passwd = UNKNOWN, int $authmode = GSLC_SSL_NO_AUTH) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function ldap_connect(string $uri = null, int $port = 389, string $wallet = UNKNOWN, string $wallet_passwd = UNKNOWN, int $authmode = GSLC_SSL_NO_AUTH) {}
function ldap_connect(?string $uri = null, int $port = 389, string $wallet = UNKNOWN, string $wallet_passwd = UNKNOWN, int $authmode = GSLC_SSL_NO_AUTH) {}

and elsewhere. These need to be explicitly marked nullable. I thought the script would throw an error for that :/

Copy link
Member

@kocsismate kocsismate Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does throw (at least I got such an exception a few weeks ago)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok.

Should I use ?string or string|null ? I think I’ve seen commits changing one for the other which is why I ask.

Copy link
Member

@kocsismate kocsismate Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I changed a few such types. Now, we exclusively use ? for nullable types where it is possible, so please use this format.

/** @param resource $link_identifier */
function ldap_unbind($link_identifier): bool {}
/** @param resource $link */
function ldap_unbind($link): bool {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over in #6172 we're changing $mysql_link to $connection. It's probably wise to do the same here. I don't know anyone anywhere that calls this thing a "link".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, it was called $link in some functions and $link_identifier in others which is why I changed to use $link everywhere.

I usually call this $ldap, I think I’ve seen $cid for connection id.

I’m not sure $connection is better, it’s way longer for sure (and for me prone to errors since we write "connexion" in french).

Are there other occurencies than mysql?
Can other people give their opinion (especially native english speakers)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @MCMic i'am also in favour of $ldap i think it make more sense in the context of a ldap library

Cheers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mysqli change ended up deciding on $mysql as the name, so $ldap would be the one to use here now.

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple suggestions for the parameter naming, mostly around using _ to separate words.

/** @param resource $link_identifier */
function ldap_unbind($link_identifier): bool {}
/** @param resource $link */
function ldap_unbind($link): bool {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mysqli change ended up deciding on $mysql as the name, so $ldap would be the one to use here now.

@MCMic
Copy link
Contributor Author

MCMic commented Sep 28, 2020

@nikic Should be good now

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @kocsismate can take a look as well. Sorry for the naming bikeshed :)

Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few questions/suggestions. And I'm also sorry for the prolonged bikeshed :)

* @return resource|false
*/
function ldap_read($link_identifier, array|string $base_dn, array|string $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $servercontrols = []) {}
function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {}
function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $size_limit = -1, int $time_limit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, @nikic proposed the same, but both openldap and php use sizelimit and timelimit in other places, it’s always have been a whole word.

I can change $attrsonly though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a big problem with diverging from these other names, but I also don't mind if these stay without the _. So I'm ok.

* @return resource|false
*/
function ldap_list($link_identifier, array|string $base_dn, array|string $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $servercontrols = []) {}
function ldap_list($ldap, array|string $base, array|string $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (and one more below)

* @deprecated since 7.4
*/
function ldap_control_paged_result($link, int $pagesize, bool $iscritical = false, string $cookie = ""): bool {}
function ldap_control_paged_result($ldap, int $pagesize, bool $iscritical = false, string $cookie = ""): bool {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function ldap_control_paged_result($ldap, int $pagesize, bool $iscritical = false, string $cookie = ""): bool {}
function ldap_control_paged_result($ldap, int $page_size, bool $critical = false, string $cookie = ""): bool {}

Could just $size work? Nevertheless, using the page_ prefix is perfectly fine for me.
$is_critical would be ok for me as well, but I think there's an agreement that we don't use the is_ prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this function is deprecated since PHP-7.4. Can it be removed in PHP-8?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be fine to drop. It looks like another deprecated function (ldap_sort) did get dropped already. I'd suggest landing that separately from this PR (just directly commit it with a note in UPGRADING).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will do that.

Copy link
Member

@nikic nikic Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we should land this today to ensure the removal goes into PHP 8.0, I've put up #6235. Does that look reasonable?

(Feel free to land your own version though, I just want to make sure it goes in...)

* @param array|string|int $retval
*/
function ldap_get_option($link_identifier, int $option, &$retval = null): bool {}
function ldap_get_option($ldap, int $option, &$retval = null): bool {}
Copy link
Member

@kocsismate kocsismate Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function ldap_get_option($ldap, int $option, &$retval = null): bool {}
function ldap_get_option($ldap, int $option, &$return_value = null): bool {}

or just $value? the manual says "This will be set to the option value.", so maybe this name would be ok.

*/
function ldap_parse_result($link, $result, &$errcode, &$matcheddn = null, &$errmsg = null, &$referrals = null, &$serverctrls = null): bool {}
function ldap_parse_result($ldap, $result, &$errcode, &$matcheddn = null, &$errmsg = null, &$referrals = null, &$controls = null): bool {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function ldap_parse_result($ldap, $result, &$errcode, &$matcheddn = null, &$errmsg = null, &$referrals = null, &$controls = null): bool {}
function ldap_parse_result($ldap, $result, &$error_code, &$matched_dn = null, &$error_message = null, &$referrals = null, &$controls = null): bool {}

$errno could also be used, but so far $error_code is what we preferred in another PR.

* @param string $retdata
* @param string $retoid
* @return resource|bool
*/
function ldap_exop($link, string $reqoid, ?string $reqdata = null, ?array $servercontrols = [], &$retdata = null, &$retoid = null) {}
function ldap_exop($ldap, string $reqoid, ?string $reqdata = null, ?array $controls = [], &$retdata = null, &$retoid = null) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using a $request_ prefix work well? And $response_data or something similar?

* @param resource $result
* @param string $retdata
* @param string $retoid
*/
function ldap_parse_exop($link, $result, &$retdata = null, &$retoid = null): bool {}
function ldap_parse_exop($ldap, $result, &$retdata = null, &$retoid = null): bool {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same questions apply :)

@MCMic
Copy link
Contributor Author

MCMic commented Sep 29, 2020

@kocsismate Should be good now, except for the deprecated functions.

Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@MCMic
Copy link
Contributor Author

MCMic commented Sep 29, 2020

I merged this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants