Oihana PHP

hasAllProperties.php

Table of Contents

Functions

hasAllProperties()  : bool
Check if all of the given properties exist in the object.

Functions

hasAllProperties()

Check if all of the given properties exist in the object.

hasAllProperties(object $object, array<string|int, mixed> $properties[, bool $notNull = false ]) : bool

If $notNull is set to true, each property must also be non-null.

Parameters
$object : object

The object to inspect

$properties : array<string|int, mixed>

List of property names to check

$notNull : bool = false

Whether to check for non-null values (default: false)

Tags
example

Usage

$doc = (object)
[
    'id'     => 123,
    'slogan' => 'Hello'
];

$props = ['id', 'slogan'];

hasAllProperties($doc, $props);        // true
hasAllProperties($doc, $props, true);  // true

$props2 = ['id', 'description'] ;
hasAllProperties($doc, $props2) ; // false (description missing)
author

Marc Alcaraz

since
1.0.0
Return values
bool

True if all properties exist (and are not null if $notNull = true)


        
On this page

Search results