phpDocumentor 通过在文本块中使用 @global 标签来执行全局变量的声明。为了支持以前的 @global 用法,有两种方法使用 @global 标签,即变量定义和函数说明。
phpDocument 不会自动解析任何 @global 标签,且每个文本块中只能使用一个 @global 标签。一个全局变量文本块必须在其它任何元素或文本块这前,否则则会出现错误。
datetype 可以是任意有效的PHP类型或者 "mixed"。
$varname 必须是与源文件中声明的全局变量一致(使用 @name 标签可以改变名称在文档中的显示)。
未完...
应用示例:
<?php
/**
* example of incorrect @global declaration #1
* @global bool $GLOBALS['baz']
* @author blahblah
* @version -6
*/
include("file.ext");
// error - element encountered before global variable declaration, docblock will apply to this include!
$GLOBALS['baz'] = array('foo', 'bar');
/**
* example of incorrect @global declaration #2
* @global parserElement $_Element
*/
/**
* error - this DocBlock occurs before the global variable definition and will apply to the function,
* ignoring the global variable completely
*/
$_Element = new parserElement;
function oopsie()
{
//...
}
/**
* example of correct @global declaration,
* even with many irrelevant things in between
* @global mixed $_GLOBALS["myvar"]
*/
// this is OK
if ($pre)
{
$thisstuff = 'is fine too';
}
$_GLOBALS["myvar"] = array("this" => 'works just fine');
/**
* example of using @name with @global
* the @name tag *must* have a $ in the name, or an error will be raised
* @global array $GLOBALS['neato']
* @name $neato
*/
$GLOBALS['neato'] = 'This variable\'s name is documented as $neato, and not as $GLOBALS[\'neato\'];
?>
Here's an example of documenting the use of a global variable in a function/method
<?php
/**
* Used to showcase linking feature of function @global
*/
class test
{
}
/**
* @global test $GLOBALS['baz']
* @name $bar
*/
$GLOBALS['bar'] = new test
/**
* example of basic @global usage in a function
* assume global variables "$foo" and "$bar" are already documented
* @global bool used to control the weather
* @global test used to calculate the division tables
* @param bool $baz
* @return mixed
*/
function function1($baz)
{
global $foo,$bar;
// note that this also works as:
// global $foo;
// global $bar;
if ($baz)
{
$a = 5;
} else
{
$a = array(1,4);
}
return $a;
}
?>
参考:http://pear.php.net/package/PhpDocumentor/docs/1.4.3/phpDocumentor/tutorial_tags.global.pkg.html