WP_CLI\Traverser

RecursiveDataStructureTraverser::create_keyprotectedWP-CLI 1.0

Create the key on the current data.

Method of the class: RecursiveDataStructureTraverser{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->create_key();

RecursiveDataStructureTraverser::create_key() code WP-CLI 2.13.0-alpha

protected function create_key() {
	if ( is_array( $this->data ) ) {
		$this->data[ $this->key ] = null;
	} elseif ( is_object( $this->data ) ) {
		$this->data->{$this->key} = null;
	} else {
		$type = gettype( $this->data );
		throw new UnexpectedValueException(
			"Cannot create key \"{$this->key}\" on data type {$type}"
		);
	}
}