21,891
社区成员
发帖
与我相关
我的任务
分享function foo($arg){
function bar(){
//这里怎样才能访问到 $arg
$n = func_get_args();
print_r($n);
}
$text = 'abc';
preg_replace("/abc/ie","bar('\\0','".$arg."')",$text);
}
foo('hello world!');
<?php
function format($text,$hs){
function bar($key,$ptn,$hs){
return $hs[$key];
}
return preg_replace("/\{\\$([^}]+?)(?::([^}]+?))?\}/ie","bar('$1','$2',\$hs)",$text);
}
echo format('I say {$text}',array('text'=>'hello world!'));
?>
function a($arg,$arg2)
{
function b()
{
$b = debug_backtrace();
foreach($b as $k=>$v)
{
if($v['function'] !== __FUNCTION__) print_r($v['args']);
}
}
b();
}
a('hello world','hello china');
$a=4;
function c(){
global $a;
$b=1;
echo $a*$b;
}
c(); class aa{
var $a;
function b(){
$b = 1;
echo intval($this -> a)*$b;
}
}
$obj = new aa();
$obj->a = 4;
$obj -> b();