downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

ReflectionParameter::getDeclaringClass> <ReflectionParameter::export
[edit] Last updated: Fri, 17 May 2013

view this page in

ReflectionParameter::getClass

(PHP 5)

ReflectionParameter::getClassGet class

Descrierea

public ReflectionClass ReflectionParameter::getClass ( void )

Gets a class.

Avertizare

Această funcție nu este documentată în prezent; este disponibilă numai lista sa de argumente.

Parametri

Această funcție nu are parametri.

Valorile întoarse

A ReflectionClass object.

Vedeți de asemenea



add a note add a note User Contributed Notes ReflectionParameter::getClass - [2 notes]
up
1
tom at r dot je
1 year ago
ReflectionParameter::getClass() will cause a fatal error (and trigger __autoload) if the class required by the parameter is not defined.

Sometimes it's useful to only know the class name without needing the class to be loaded.

Here's a simple function that will retrieve only the class name without requiring the class to exist:

<?php
function getClassName(ReflectionParameter $param) {
   
preg_match('/\[\s\<\w+?>\s([\w]+)/s', $param->__toString(), $matches);
    return isset(
$matches[1]) ? $matches[1] : null;
}
?>
up
1
infernaz at gmail dot com
2 years ago
The method returns ReflectionClass object of parameter type class or NULL if none.

<?php

class A {
    function
b(B $c, array $d, $e) {
    }
}
class
B {
}

$refl = new ReflectionClass('A');
$par = $refl->getMethod('b')->getParameters();

var_dump($par[0]->getClass()->getName());  // outputs B
var_dump($par[1]->getClass());  // note that array type outputs NULL
var_dump($par[2]->getClass());  // outputs NULL

?>

 
show source | credits | sitemap | contact | advertising | mirror sites