1.php 文件
<?php
function uses1() {
$args = func_get_args();
foreach($args as $arg) {
$name = strtolower($arg);
require("phpb2b/upload/libraries/core/models/".$name.'.php');
}
}
uses1("comm");
echo $a;
?>
$a 就是输不出来 路径没问题
comm.php 里写的是 <?php
$a="beijing";
return $a;
?>
请教各位大侠,这个到底哪里错了?
<?php
function uses1() {
$args = func_get_args();
foreach($args as $arg) {
$name = strtolower($arg);
require("phpb2b/upload/libraries/core/models/".$name.'.php');
}
}
uses1("comm");
echo $a;
?>
$a 就是输不出来 路径没问题
comm.php 里写的是 <?php
$a="beijing";
return $a;
?>
请教各位大侠,这个到底哪里错了?
1、function uses1(),里面没有参数,你却用uses1("comm");调用
2、$a没有定义任何内容,当然没有输出。即使在comm.php定义了,但comm.php已经return了
$args = func_get_args();
这个函数可以获得参数
那有没有办法,可以在方法里面require 在外面调用变量
//正确
function fun(){
class A{
function t(){
echo 'a';
}
}
return new A();
}
$a = fun();
$a->t();//错误
function fun(){
class A{
function t(){
echo 'a';
}
}
}
$a = new A();
$a->t();
function fun(){
class A{
function t(){
echo 'a';
}
}
return new A();
}
$a = fun();
$a->t();
……
[/Quote]第二种方法如果在加一句 fun() 然后在函数外实例化类 调用方法也是可以的