Core\Ldap\Change::remove
Core\Ldap\Change::remove(
string $attribute,
mixed $value,
): Core\Ldap\ChangeReturns 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 asdescription. It cannot betainted.$valuemixedOne value, or a list of values. A value is written in the form the methods ofEntryreturn it, such as anint, aUuidor anInstant.
Return value
Returns Core\Ldap\Change. The change.
Errors
LogicErrorattributeis 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";1Swap 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";2Which 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"; }}mail: yesmsDS-cloudExtensionAttribute1: yes2.5.4.3: yes1mail: noe mail: no