Oihana PHP

omit.php

Table of Contents

Functions

omit()  : object
Removes the specified public properties from an object.

Functions

omit()

Removes the specified public properties from an object.

omit(object $object, array<int, string> $keys) : object

Returns a new stdClass containing every public property of the source object except the listed ones. The source object is never modified. This is the inverse of pick().

Parameters
$object : object

The source object.

$keys : array<int, string>

The list of property names to remove.

Tags
example
use function oihana\core\objects\omit;

$user = (object) [ 'id' => 42 , 'name' => 'Alice' , 'password' => 'secret' ] ;

$result = omit( $user , [ 'password' ] ) ;
// (object) [ 'id' => 42 , 'name' => 'Alice' ]
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
object

A new stdClass without the omitted properties.

On this page

Search results