Skip to content

Core\Ldap\Change::remove

Returns a Core\Ldap\Change that removes values from one attribute of a directory entry. The other values of the attribute stay.

The change does nothing on its own. You put it in a list and pass the list to a connection's modify method. modify sends every change in the list in one request, so the server makes all of them or none of them. A remove and an add in one list replace one value with another.

Good to know: the entry must have the value. If it does not, modify throws an LdapError and the server changes nothing. To remove every value of an attribute, use removeAll. A name that is not an attribute name throws a LogicError at once.

Parameters

  • $attributestringThe attribute's name, such as description. It cannot be tainted.
  • $valuemixedOne value, or a list of values. A value is written in the form the methods of Entry return it, such as an int, a Uuid or an Instant.

Return value

Returns Core\Ldap\Change. The change.

Errors

  • LogicErrorattribute is not an attribute name.

Examples

Remove one number

<?nvs
// Shows how to prepare a change that removes one phone number from a user.
var $old = Core\Ldap\Change::remove('otherTelephone', '+43 1 111 2222');
// The other numbers of `otherTelephone` stay. This prints 1.
array<Core\Ldap\Change> $changes = [$old];
echo Core\Arr::count($changes), "\n";
Output
1

Swap one value

<?nvs
// Shows how to replace one value of an attribute and keep the others.
// `modify` sends both changes in one request. The server makes both or none.
array<Core\Ldap\Change> $changes = [
Core\Ldap\Change::remove('otherTelephone', '+43 1 111 2222'),
Core\Ldap\Change::add('otherTelephone', '+43 1 555 6666'),
];
// This prints 2.
echo Core\Arr::count($changes), "\n";
Output
2

Which names work

<?nvs
// Shows which attribute names a change accepts.
// A name starts with a letter. A dotted number such as 2.5.4.3 also works.
// This prints yes for the first three names and no for the last two.
array<string> $names = ['mail', 'msDS-cloudExtensionAttribute1', '2.5.4.3', '1mail', 'e mail'];
foreach ($names as string $name) {
try {
var $change = Core\Ldap\Change::remove($name, 'old value');
echo $name, ": yes\n";
} catch (LogicError $refusal) {
echo $name, ": no\n";
}
}
Output
mail: yes
msDS-cloudExtensionAttribute1: yes
2.5.4.3: yes
1mail: no
e mail: no