Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

property_exists()

Detect a declared property, even when private, uninitialized, or set to null.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

property_exists(object|string $object_or_class, string $property): bool

Detect a declared property, even when private, uninitialized, or set to null. An object argument can also reveal a dynamic property on that instance. A value computed exclusively by __get does not establish an actual property of that name. A private field declared only in a parent is absent when checking the child class.

Signature

property_exists(object|string $object_or_class, string $property): bool

Example output

[true,true,false,7]
false

Examples

<?php
class Meter { private ?int $limit=null; public int $count; public function __get($name){return 7;} }
$m=new Meter(); echo json_encode([property_exists($m,"limit"),property_exists($m,"count"),property_exists($m,"computed"),$m->computed]);
class SubMeter extends Meter {} echo "\n", json_encode(property_exists(SubMeter::class,"limit"));

Result

[true,true,false,7]
false

Sources