Baza znanjaCentar za ispite
HRHrvatski
Odaberi jezik13

CKTIS / PHP

ReflectionClass

Pregledava klasu i stvara instance. newInstanceArgs pokreće konstruktor s argumentima, a isInstantiable unaprijed izdvaja sučelja i apstraktne klase.

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

Sintaksa

new ReflectionClass($classOrObject)

Pregledava klasu i stvara instance. newInstanceArgs pokreće konstruktor s argumentima, a isInstantiable unaprijed izdvaja sučelja i apstraktne klase. Privatni konstruktor tom metodom ne postaje javan.

class Meter {public function __construct(public int $n){}}
$ref=new ReflectionClass(Meter::class); $obj=$ref->newInstanceArgs([7]);
echo json_encode([$ref->isInstantiable(),$obj->n,(new ReflectionClass(Countable::class))->isInstantiable()]);
[true,7,false]

Primjeri

<?php
class Meter {public function __construct(public int $n){}}
$ref=new ReflectionClass(Meter::class); $obj=$ref->newInstanceArgs([7]);
echo json_encode([$ref->isInstantiable(),$obj->n,(new ReflectionClass(Countable::class))->isInstantiable()]);

Rezultat

[true,7,false]

Izvori