Skip to content

Commit b3698ed

Browse files
ptomulikkocsismate
authored andcommitted
Promote warning to exception in ldap_set_rebind_proc()
From now on, ldap_set_rebind_proc() will only accept callable or null as argument 2. Closes GH-5763
1 parent 3006789 commit b3698ed

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ PHP 8.0 UPGRADE NOTES
275275

276276
- LDAP:
277277
. The deprecated function ldap_sort has been removed.
278+
. The interface of ldap_set_rebind_proc has changed; the $callback parameter
279+
does not accept empty string anymore; null value shall be used instead.
278280

279281
- Mbstring:
280282
. The mbstring.func_overload directive has been removed. The related

ext/ldap/ldap.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,7 +3736,7 @@ int _ldap_rebind_proc(LDAP *ldap, const char *url, ber_tag_t req, ber_int_t msgi
37363736
}
37373737
/* }}} */
37383738

3739-
/* {{{ proto bool ldap_set_rebind_proc(resource link, string callback)
3739+
/* {{{ proto bool ldap_set_rebind_proc(resource link, ?callable callback)
37403740
Set a callback function to do re-binds on referral chasing. */
37413741
PHP_FUNCTION(ldap_set_rebind_proc)
37423742
{
@@ -3751,7 +3751,7 @@ PHP_FUNCTION(ldap_set_rebind_proc)
37513751
RETURN_THROWS();
37523752
}
37533753

3754-
if (Z_TYPE_P(callback) == IS_STRING && Z_STRLEN_P(callback) == 0) {
3754+
if (Z_TYPE_P(callback) == IS_NULL) {
37553755
/* unregister rebind procedure */
37563756
if (!Z_ISUNDEF(ld->rebindproc)) {
37573757
zval_ptr_dtor(&ld->rebindproc);
@@ -3763,10 +3763,8 @@ PHP_FUNCTION(ldap_set_rebind_proc)
37633763

37643764
/* callable? */
37653765
if (!zend_is_callable(callback, 0, NULL)) {
3766-
zend_string *callback_name = zend_get_callable_name(callback);
3767-
php_error_docref(NULL, E_WARNING, "Two arguments expected for '%s' to be a valid callback", ZSTR_VAL(callback_name));
3768-
zend_string_release_ex(callback_name, 0);
3769-
RETURN_FALSE;
3766+
zend_argument_type_error(2, "must be a valid callback or null, %s given", zend_zval_type_name(callback));
3767+
RETURN_THROWS();
37703768
}
37713769

37723770
/* register rebind procedure */

ext/ldap/ldap.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,8 @@ function ldap_parse_result($link, $result, &$errcode, &$matcheddn = null, &$errm
260260
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
261261
/**
262262
* @param resource $link
263-
* @param callable $callback
264263
*/
265-
function ldap_set_rebind_proc($link, $callback): bool {}
264+
function ldap_set_rebind_proc($link, ?callable $callback): bool {}
266265
#endif
267266

268267
#ifdef HAVE_LDAP_START_TLS_S

ext/ldap/ldap_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 53051e130a22dc519676c7a91529d2f9f7d1e6ad */
2+
* Stub hash: c9ce0e98ab386130b6332ae017808bec67b1cd07 */
33

44
#if defined(HAVE_ORALDAP)
55
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0)
@@ -280,7 +280,7 @@ ZEND_END_ARG_INFO()
280280
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
281281
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_set_rebind_proc, 0, 2, _IS_BOOL, 0)
282282
ZEND_ARG_INFO(0, link)
283-
ZEND_ARG_INFO(0, callback)
283+
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 1)
284284
ZEND_END_ARG_INFO()
285285
#endif
286286

ext/ldap/tests/ldap_set_rebind_proc_basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function rebind_proc ($ds, $ldap_url) {
2525

2626
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
2727
var_dump(ldap_set_rebind_proc($link, "rebind_proc"));
28-
var_dump(ldap_set_rebind_proc($link, ""));
28+
var_dump(ldap_set_rebind_proc($link, null));
2929
?>
3030
--EXPECT--
3131
bool(true)

ext/ldap/tests/ldap_set_rebind_proc_error.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ function rebind_proc ($ds, $ldap_url) {
3333
}
3434

3535
$link = ldap_connect($host, $port);
36-
var_dump(ldap_set_rebind_proc($link, "rebind_proc_inexistent"));
36+
try {
37+
$result = ldap_set_rebind_proc($link, "rebind_proc_inexistent");
38+
} catch(\TypeError $error) {
39+
echo $error->getMessage(), "\n";
40+
}
3741
?>
3842
--EXPECTF--
39-
Warning: ldap_set_rebind_proc(): Two arguments expected for 'rebind_proc_inexistent' to be a valid callback in %s on line %d
40-
bool(false)
43+
ldap_set_rebind_proc(): Argument #2 ($callback) must be a valid callback or null, string given

0 commit comments

Comments
 (0)