DiDom\Element::setValue PHP Method

setValue() public method

Set the value of this node.
public setValue ( string $value ) : Element
$value string The new value of the node
return Element
    public function setValue($value)
    {
        if (is_numeric($value)) {
            $value = (string) $value;
        }
        if (!is_string($value) and $value !== null) {
            throw new InvalidArgumentException(sprintf('%s expects parameter 1 to be string, %s given', __METHOD__, is_object($value) ? get_class($value) : gettype($value)));
        }
        $this->node->nodeValue = $value;
        return $this;
    }

Usage Example

示例#1
0
 public function testSetValue()
 {
     $element = new Element('span', 'hello');
     $element->setValue('test');
     $this->assertEquals('test', $element->text());
 }