Record::subscripting - jcobban/Genealogy GitHub Wiki

$record[$fieldName]

Up: class Record

Subscript notation can be used either to obtain or change the value of an field. If this is used as part of specifying an expression whose value is to be obtained this notation calls method $record->get($fieldName). If invoked as the left hand side of an assignment to alter or define the value of a field this calls $record->set($fieldName, $newValue). Therefore all of the class-specific functionality of those methods applies to referencing fields by subscripts. In many cases using subscripts, as opposed to calling the functions get and set, makes it easier to understand the action of statements.

For example:

$idir			= $person['idir'];
$person['givenname']	= 'John';
if (isset($person['birthplace'])) ...
unset($person['extra']);		// only for temporary fields

Support for subscript notation is implemented by supporting the interface ArrayAccess. This consist of implementing the following methods:

public offsetExists ( mixed $offset ) : bool
public offsetGet ( mixed $offset ) : mixed
public offsetSet ( mixed $offset , mixed $value ) : void
public offsetUnset ( mixed $offset ) : void

Although this permits treating an instance of Record as if it was an array for many purposes it does not include support for the PHP functions that start with array_ such as array_key_exists.

Next: $record->selecte