CKTIS / PHP
property_exists()
Rileva una proprietà dichiarata, anche privata, non inizializzata o impostata a null.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
property_exists(object|string $object_or_class, string $property): boolRileva una proprietà dichiarata, anche privata, non inizializzata o impostata a null. Passando un oggetto rileva anche le proprietà dinamiche di quell’istanza. Un nome gestito esclusivamente da __get non costituisce una proprietà. Nel controllo sulla classe figlia non compare una proprietà privata dichiarata solo nella classe padre.
Firma
property_exists(object|string $object_or_class, string $property): bool
Output dell’esempio
[true,true,false,7]
false
Esempi
<?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"));
Risultato
[true,true,false,7] false