Core\Ldap\Dn::parent
$dn->parent(): ?Core\Ldap\DnReturns the DN one level up, without its first part. For CN=Ann,OU=Staff,DC=example,DC=test the result is OU=Staff,DC=example,DC=test.
Use it to find the group or the unit that an entry is in.
Good to know: a DN with only one part has no parent, and the result is null.
Return value
Returns ?Core\Ldap\Dn. The parent DN, or null when this DN has only one part.
Examples
One level up
<?nvs// Shows how to find the unit that a person's entry is in.
var $person = Core\Ldap\Dn::parse('CN=Ann,OU=Staff,DC=example,DC=test');// This prints OU=Staff,DC=example,DC=test.echo $person->parent()?->toString() ?? 'none', "\n";OU=Staff,DC=example,DC=testWalk to the top
<?nvs// Shows how to go up a DN one level at a time, until there is no parent.
Core\Ldap\Dn $at = Core\Ldap\Dn::parse('CN=Ann,OU=Staff,DC=example,DC=test');// This prints four lines, and the last one is DC=test.while (true) { echo $at->toString(), "\n"; var $up = $at->parent(); if ($up == null) { break; } else { $at = $up; }}CN=Ann,OU=Staff,DC=example,DC=testOU=Staff,DC=example,DC=testDC=example,DC=testDC=testNo parent
<?nvs// Shows the result for a DN with only one part.
var $top = Core\Ldap\Dn::of('DC', 'test');// The result is `null`, so this prints no parent.if ($top->parent() == null) { echo "no parent\n";}no parent