ensureObjectPath.php
Table of Contents
Functions
- ensureObjectPath() : object
- Ensures that a given property of an object is initialized as an object.
Functions
ensureObjectPath()
Ensures that a given property of an object is initialized as an object.
& ensureObjectPath(object &$current, string $segment) : object
If the property does not exist or is not an object, it will be replaced with a new stdClass instance. The function returns a reference to the nested object, allowing direct modification.
This is useful when building or navigating nested object structures dynamically.
Parameters
- $current : object
-
The current object in which the property is ensured.
- $segment : string
-
The property name to ensure as an object.
Tags
Return values
object —A reference to the ensured nested object (stdClass).