The second parameter doesn't exactly do, what you would expect. So use the method with care.
If it is TRUE the method works like a switch.
If it is FALSE the method turns ID setting off.
A unit test demonstrates the exact behaviour:
public function testSetIdAttribute() {
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', TRUE);
$this->assertType('DOMElement', $this->dom->getElementById('testChild'));
$this->assertNotNull($this->dom->getElementById('testChild'));
// TRUE switches between on and off, while false turns it off.
$this->child->setIdAttribute('id', TRUE);
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', TRUE);
$this->assertNotNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', TRUE);
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', TRUE);
$this->assertNotNull($this->dom->getElementById('testChild'));
// FALSE turns off and not on any more.
$this->child->setIdAttribute('id', FALSE);
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', FALSE);
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', FALSE);
$this->assertNull($this->dom->getElementById('testChild'));
}
DOMElement->setIdAttribute()
(No version information available, might be only in CVS)
DOMElement->setIdAttribute() — Declares the attribute specified by name to be of type ID
Descrição
DOMElement
void setIdAttribute
( string $name
, bool $isId
)
Declares the attribute name to be of type ID.
Parâmetros
- name
-
The name of the attribute.
- isId
-
Set it to TRUE if you want name to be of type ID, FALSE otherwise.
Valor Retornado
Não há valor retornado.
Erros
- DOM_NO_MODIFICATION_ALLOWED_ERR
-
Raised if the node is readonly.
- DOM_NOT_FOUND
-
Raised if name is not an attribute of this element.
User Contributed Notes
DOMElement->setIdAttribute()
DOMElement->setIdAttribute()
ElmarHinz
20-May-2007 04:54
20-May-2007 04:54

DOMElement->setAttributeNS()