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
Popis
class DOMElement {void setIdAttribute ( string $name, bool $isId )
}
Declares the attribute name to be of type ID.
Seznam parametrů
- name
The name of the attribute.
- isId
Set it to TRUE if you want name to be of type ID, FALSE otherwise.
Návratové hodnoty
Nevrací se žádná hodnota.
Errors/Exceptions
- DOM_NO_MODIFICATION_ALLOWED_ERR
Raised if the node is readonly.
- DOM_NOT_FOUND
Raised if name is not an attribute of this element.
Viz také
| DOMDocument->getElementById() |
| DOMElement->setIdAttributeNode() |
| DOMElement->setIdAttributeNS() |
DOMElement->setIdAttribute()
ElmarHinz
20-May-2007 12:54
20-May-2007 12:54
