Oihana PHP

NullsOption

Defines constants for the handling of null values in merge operations.

This class standardizes the possible behaviors for null values:

  • SKIP : ignore null values when merging if a key exists.
  • KEEP : keep null values only if the key does not exist.
  • OVERWRITE : overwrite existing values with null.
Tags
author

Marc Alcaraz (ekameleon)

author

Marc Alcaraz

since
1.0.8
since
1.0.8
example
use oihana\core\options\NullsOption;
use oihana\core\options\MergeOption;
use function oihana\core\arrays\merge;

$a = ['foo' => 'bar', 'count' => 2];
$b = ['foo' => null, 'extra' => null];

// Use 'keep' behavior for nulls
$result = merge($a, $b, MergeOption::normalize
([
    MergeOption::NULLS => NullsOption::KEEP
]));

// Result:
// [
//   'foo'   => 'bar',
//   'count' => 2,
//   'extra' => null
// ]

Table of Contents

Constants

KEEP  = 'keep'
Keep null values only if the key does not exist.
OVERWRITE  = 'overwrite'
Overwrite existing values with null.
SKIP  = 'skip'
Skip null values when merging (default behavior).

Methods

all()  : array<string|int, string>
Returns the list of valid options.
isValid()  : bool
Checks if a given value is a valid null behavior option.

Constants

KEEP

Keep null values only if the key does not exist.

public mixed KEEP = 'keep'

Type: string

OVERWRITE

Overwrite existing values with null.

public mixed OVERWRITE = 'overwrite'

Type: string

SKIP

Skip null values when merging (default behavior).

public mixed SKIP = 'skip'

Type: string

Methods

all()

Returns the list of valid options.

public static all() : array<string|int, string>
Return values
array<string|int, string>

isValid()

Checks if a given value is a valid null behavior option.

public static isValid(string $value) : bool
Parameters
$value : string
Return values
bool

        
On this page

Search results