HTML::offsetGet()
Gets the attribute’s value.
Table of Contents
Description
HTML::offsetGet(mixed $key): ?string;This method is a requirement to be able to implement the ArrayAccess interface and aims to make the object data accessible using array access syntax. You won’t use this method directly, it will be executed automatically when you try to get an attribute’s value with array access syntax. If the attribute does not exist in the node, this method returns null.
Passing a numeric key is considered as getting the data directly from the source. Which means that calling attribute 0 returns the node name, calling attribute 1 returns the node content (if node is void, this attribute returns false), calling attribute 2 returns the node attributes.
Example
$node = new HTML('<input disabled name="test" value="aaa"bbb">');
test($node['asdf']); // Returns `null` because attribute `asdf` does not exist
test($node['disabled']); // Returns `true` because attribute `disabled` does exist and is value-less
test($node['name']); // Returns `'test'` because attribute `name` does exist
test($node['value']); // Returns `'aaa"bbb'` because attribute `value` does exist
test($node[0]); // Returns `'input'`
test($node[1]); // Returns `false` because node is void
test($node[2]); // Returns `['disabled' => true, 'name' => 'test', 'value' => 'aaa"bbb']`HTML::_()
The dynamic method initiator.
HTML::__call()
Proxy for missing methods.
HTML::__callStatic()
Proxy for missing static methods.
HTML::__construct()
The constructor.
HTML::__serialize()
Provides data to be serialized.
HTML::__toString()
Converts the HTML object to string.
HTML::__unserialize()
Converts the serialized data back to its object.
HTML::count()
Nothing.
HTML::jsonSerialize()
Returns the data to be serialized as JSON.
HTML::offsetExists()
Checks if an attribute exists.
HTML::offsetGet()
Gets the attribute’s value.
HTML::offsetSet()
Sets the attribute’s value.
HTML::offsetUnset()
Deletes an attribute.