1--TEST--
2Programming errors (Value/Type errors) for ldap_add(_ext)(), ldap_mod_replace(_ext)(), ldap_mod_add(_ext)(), and ldap_mod_del(_ext)() with references
3--EXTENSIONS--
4ldap
5--FILE--
6<?php
7
8/* ldap_add(_ext)(), ldap_mod_replace(_ext)(), ldap_mod_add(_ext)(), and ldap_mod_del(_ext)() share an underlying C function */
9/* We are assuming 3333 is not connectable */
10$ldap = ldap_connect('ldap://127.0.0.1:3333');
11$valid_dn = "cn=userA,something";
12
13/* Taken from the existing ldap_add() PHP documentation */
14$valid_entries = [
15    'attribute1' => 'value',
16    'attribute2' => [
17        'value1',
18        'value2',
19    ],
20];
21
22$obj = new stdClass();
23$dict_key_value_not_string = [
24    'attribute1' => &$obj,
25    'attribute2' => [
26        'value1',
27        'value2',
28    ],
29];
30try {
31    var_dump(ldap_add($ldap, $valid_dn, $dict_key_value_not_string));
32} catch (Throwable $e) {
33    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
34}
35
36$empty_list = [];
37$dict_key_multi_value_empty_list = [
38    'attribute1' => 'value',
39    'attribute2' => &$empty_list,
40];
41try {
42    var_dump(ldap_add($ldap, $valid_dn, $dict_key_multi_value_empty_list));
43} catch (Throwable $e) {
44    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
45}
46
47$empty_list = [];
48$dict_key_multi_value_not_list_of_strings = [
49    'attribute1' => 'value',
50    'attribute2' => [
51        'value1',
52        &$empty_list,
53    ],
54];
55try {
56    var_dump(ldap_add($ldap, $valid_dn, $dict_key_multi_value_not_list_of_strings));
57} catch (Throwable $e) {
58    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
59}
60
61$obj = new stdClass();
62$dict_key_multi_value_not_list_of_strings2 = [
63    'attribute1' => 'value',
64    'attribute2' => [
65        'value1',
66        &$obj,
67    ],
68];
69try {
70    var_dump(ldap_add($ldap, $valid_dn, $dict_key_multi_value_not_list_of_strings2));
71} catch (Throwable $e) {
72    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
73}
74/* We don't check that values have nul bytes as the length of the string is passed to LDAP */
75
76?>
77--EXPECT--
78Error: Object of class stdClass could not be converted to string
79ValueError: ldap_add(): Argument #3 ($entry) list of attribute values must not be empty
80TypeError: LDAP value must be of type string|int|bool, array given
81TypeError: LDAP value must be of type string|int|bool, stdClass given
82