XML::offsetExists()

Checks if an attribute exists.

Table of Contents
  1. Description
  2. Example

Description

XML::offsetExists(mixed $key): bool;

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 check the existence of an attribute with array access syntax. This method checks if an attribute exists in the node and will only work when checked using empty() or isset() language construct.

Passing a numeric key is considered as checking the data directly from the source. Which means that checking attribute 0 tests the node name, checking attribute 1 tests the node content, checking attribute 2 tests the node attributes.

Example

$node = new XML('<input disabled="disabled" name="test" value=""/>');

test(empty($node['disabled'])); // Returns `false`
test(empty($node['value'])); // Returns `true`
test(isset($node['name'])); // Returns `true`

XML::offsetExists()

Checks if an attribute exists.