TraverseObject::using()

Since v1.8.0

Description

TraverseObject::using() - iterate over an object's public properties

use GanbaroDigital\MissingBits\ListTraversals\TraverseObject;
void TraverseObject::using(object $list, string $listName, callable $callable);

Parameters

TraverseObject::using() takes three parameters:

$callable is any PHP callable. It should take three parameters:

$callable = function($value, $key, $name) {
    // .. do something here
}

For example:

$myList = (object)[
    "harry" => "sally",
    "alice" => "wonderland"
];
$callable = function($value, $key, $name) {
    echo "$name is $value" . PHP_EOL;
}
TraverseArray::using($myList, 'myList', $callable);

will output:

$myList->harry is sally
$myList->alice is wonderland

Return Value

TraverseObject::using() does not return a value.

Throws

TraverseObject::using() throws an InvalidArgumentException if $list is not a PHP object.

Works With

TraverseObject::using() and traverse_object() are supported on these versions of PHP:

PHP Version Works?
5.5 Yes
5.6 Yes
7.0 Yes
HHVM Yes