public function testGetExtensionName() { self::assertEquals($this->php_fctM1->getExtensionName(), $this->fctM1->getExtensionName()); self::assertEquals($this->php_fctM2->getExtensionName(), $this->fctM2->getExtensionName()); self::assertEquals($this->php_fctM3->getExtensionName(), $this->fctM3->getExtensionName()); self::assertEquals($this->php_fct_method_exists->getExtensionName(), $this->fct_method_exists->getExtensionName()); }
/** * Import a single function * * @param string extension * @param string function * @return [:bool] import * @throws lang.IllegalArgumentException if extension or function don't exist */ public function importSelected($extension, $function) { try { $f = new \ReflectionFunction($function); } catch (\ReflectionException $e) { throw new IllegalArgumentException($e->getMessage()); } if ($extension === strtolower($fe = $f->getExtensionName())) { return [$function => true]; } else { throw new IllegalArgumentException('Function ' . $function . ' is not inside extension ' . $extension . ' (but ' . ($fe ?: '(n/a)') . ')'); } }
/** * Called for every reflected function * * @param \ReflectionFunction $function * @param string $generated * @param $generated */ public function generateFunction(\ReflectionFunction $function, $generated) { $this->addToExtension($function->getExtensionName(), $generated); }
function gen_docs($name, $type) { /* {{{ */ global $OPTION, $INFO; if ($type & DOC_EXTENSION) { try { $extension = new ReflectionExtension($name); $INFO['actual_extension'] = $name; write_doc($extension, DOC_EXTENSION); foreach ($extension->getClasses() as $class) { gen_docs($class->name, DOC_CLASS); } foreach ($extension->getFunctions() as $function) { gen_docs($function->name, DOC_FUNCTION); } } catch (Exception $e) { die('Error: ' . $e->getMessage() . "\n"); } } else { if ($type & DOC_FUNCTION) { try { $function = new ReflectionFunction($name); if (!$INFO['actual_extension']) { if ($extname = $function->getExtensionName()) { $INFO['actual_extension'] = $extname; } else { add_warning("The function {$name} lacks Reflection information"); } } write_doc($function, DOC_FUNCTION); } catch (Exception $e) { die('Error: ' . $e->getMessage() . "\n"); } } else { if ($type & DOC_METHOD) { try { $class = new ReflectionClass($OPTION['class']); if (!$INFO['actual_extension']) { if ($extname = $class->getExtensionName()) { $INFO['actual_extension'] = $extname; } else { add_warning("The method {$name} lacks Reflection information"); } } foreach ($class->getMethods() as $method) { /* Don't get the inherited methods */ if ($method->getDeclaringClass()->name == $class->name && (is_array($OPTION['method']) && in_array(strtolower($method->getName()), $OPTION['method']) || $OPTION['method'] == strtolower($method->getName()))) { write_doc($method, $method->isConstructor() ? DOC_CONSTRUCTOR : DOC_METHOD); } } } catch (Exception $e) { die('Error: ' . $e->getMessage() . "\n"); } } else { if ($type & DOC_CLASS) { try { $class = new ReflectionClass($name); if (!$INFO['actual_extension']) { if ($extname = $class->getExtensionName()) { $INFO['actual_extension'] = $extname; } else { add_warning("The class {$name} lacks Reflection information"); } } write_doc($class, DOC_CLASS); foreach ($class->getMethods() as $method) { /* Don't get the inherited methods */ if ($method->getDeclaringClass()->name == $class->name) { write_doc($method, $method->isConstructor() ? DOC_CONSTRUCTOR : DOC_METHOD); } } } catch (Exception $e) { die('Error: ' . $e->getMessage() . "\n"); } } } } } }
$funcs = get_defined_functions(); foreach ($funcs['internal'] as $func) { $rf = new ReflectionFunction($func); $info = array('kind' => 'f', 'namespace' => $rf->getNamespaceName()); $params = array(); foreach ($rf->getParameters() as $rp) { $class = ''; if (!defined('HHVM_VERSION')) { $class = $rp->getClass(); } $param = ''; if ($class) { $param = $class->getName() . ' '; } elseif ($rp->isArray()) { $param = 'array '; } $param .= '$' . $rp->getName(); if ($rp->isOptional() && $rf->isUserDefined()) { $param .= '=' . json_encode($rp->getDefaultValue()); } $params[] = $param; } $info['type'] = '(' . implode(', ', $params) . ')'; if ($rf->isInternal()) { $filename = '(ext-' . $rf->getExtensionName() . ')'; } else { $filename = str_replace($base, '', $rf->getFileName()); } fwrite($fp, implode("\t", array($rf->getName(), $filename, $rf->getStartLine() . ';"', '')) . $build($info) . PHP_EOL); } });
/** * Returns NULL or the extension the function belongs to * * @return ezcReflectionExtension Extension the function belongs to */ public function getExtension() { if ($this->getExtensionName() === false) { return null; } else { if ($this->reflectionSource instanceof ReflectionFunction) { return new ezcReflectionExtension($this->reflectionSource->getExtension()); } else { // using the name, since otherwhise the object would be treated like an // external reflection implementation and that would decrease performance return new ezcReflectionExtension(parent::getExtensionName()); } } }
<?php function foo() { } $function = new ReflectionFunction('sort'); var_dump($function->getExtensionName()); $function = new ReflectionFunction('foo'); var_dump($function->getExtensionName());
<?php $f = new ReflectionFunction("sleep"); var_dump($f->getExtensionName());