PHP's is_object in TypeScript

How to use

Install via yarn add locutus and import: import { is_object } from 'locutus/php/var/is_object'.

Or with CommonJS: const { is_object } = require('locutus/php/var/is_object')

Use a bundler that supports tree-shaking so you only ship the functions you actually use. Vite, webpack, Rollup, and Parcel all handle this. For server-side use this is less of a concern.

Examples

These examples are extracted from test cases that automatically verify our functions against their native counterparts.

#codeexpected result
1is_object('23')false
2is_object({foo: 'bar'})true
3is_object(null)false

Dependencies

This function uses the following Locutus functions:

Here's what our current TypeScript equivalent to PHP's is_object looks like.

import { isPhpAssocObject, type PhpAssoc, type PhpRuntimeValue } from '../_helpers/_phpTypes.ts'

type ObjectValue = PhpRuntimeValue

export function is_object(mixedVar: ObjectValue): mixedVar is PhpAssoc<ObjectValue> {
// discuss at: https://locutus.io/php/is_object/
// original by: Kevin van Zonneveld (https://kvz.io)
// improved by: Legaev Andrey
// improved by: Michael White (https://getsprink.com)
// example 1: is_object('23')
// returns 1: false
// example 2: is_object({foo: 'bar'})
// returns 2: true
// example 3: is_object(null)
// returns 3: false

return isPhpAssocObject(mixedVar)
}

Improve this function

Locutus is a community effort following The McDonald's Theory: we ship first iterations, hoping others will improve them. If you see something that could be better, we'd love your contribution.

View on GitHub · Edit on GitHub · View Raw


« More PHP var functions


Star