objects
Table of Contents
Functions
- compress() : object
- Compress the passed in object by removing all properties that match given conditions.
- set() : object
- Sets a value in an object using a key path.
Functions
compress()
Compress the passed in object by removing all properties that match given conditions.
compress(object $object[, array{conditions: callable|callable[], depth: null|int, excludes: string[], recursive: bool, throwable: bool} $options = [] ][, int $currentDepth = 0 ]) : object
Parameters
- $object : object
-
The object to compress.
- $options : array{conditions: callable|callable[], depth: null|int, excludes: string[], recursive: bool, throwable: bool} = []
-
Optional configuration:
- 'conditions' (callable|array
) : One or more functions used to determine whether a value should be removed. - 'depth' (array
) : List of property names to exclude from filtering. - 'excludes' (array
) : List of property names to exclude from filtering. - 'recursive' (bool) : If true (default), recursively compress nested objects.
- 'throwable' (bool) : If true (default), throws InvalidArgumentException for invalid callbacks.
- 'conditions' (callable|array
- $currentDepth : int = 0
-
Used internally to track recursion depth.
Tags
Return values
object —The compressed object, with properties removed according to the provided conditions.
set()
Sets a value in an object using a key path.
set(object $object, string|null $key, mixed $value[, string $separator = '.' ][, bool $copy = false ][, array<string|int, mixed>|string|callable|null $classFactory = null ]) : object
Supports dot notation for nested properties. Intermediate objects are created if needed.
Parameters
- $object : object
-
The object to modify (or copy).
- $key : string|null
-
The key path to set (e.g. 'user.address.country'). If null, replaces entire object.
- $value : mixed
-
The value to set.
- $separator : string = '.'
-
The separator used in the key path. Default is '.'.
- $copy : bool = false
-
If true, returns a deep copy of the object with the modification.
- $classFactory : array<string|int, mixed>|string|callable|null = null
-
A class name, factory callable, or array path => className to create intermediate objects (default: stdClass).
Tags
Return values
object —The modified (or copied and modified) object.