【发布时间】:2013-07-18 02:21:59
【问题描述】:
主要问题还是一样:
这是我的项目
/
| index.php
|-test1
| test.php
test.php
<?php
echo $variable;
?>
index.php
<?php
$variable = "<br>index";
echo 'test<br>';
$full_path = dirname(__FILE__)."/test1";
$adm_extension = array( "php");
if (is_dir($full_path)) {
if (($handle = opendir($full_path))) {
while ($file = readdir($handle)) {
if (is_file($full_path . '/' . $file)) {
$item_path = $full_path . '/' . $file;
$extension = pathinfo($item_path, PATHINFO_EXTENSION);
if (in_array($extension, $adm_extension)) {
require $item_path;
}
}
}
}
}
它就像一个魅力,输出是:
test
index
如果我想将此功能封装在这样的函数中:
index1.php
$variable = "<br>index";
echo 'test<br>';
$full_path = dirname(__FILE__)."/test1";
$adm_extension = array( "php" );
function rTest($full_path, $adm_extension){
if (is_dir($full_path)) {
if (($handle = opendir($full_path))) {
while ($file = readdir($handle)) {
if (is_file($full_path . '/' . $file)) {
$item_path = $full_path . '/' . $file;
$extension = pathinfo($item_path, PATHINFO_EXTENSION);
if (in_array($extension, $adm_extension)) {
require $item_path;
}
}
}
}
}
}
rTest($full_path, $adm_extension);
我知道了:
( ! ) Notice: Undefined variable: variable in C:\wamp\www\sandbox\test1\test.php on line 3
有什么线索吗??
【问题讨论】:
-
不确定它是否与自动加载有关。您在第 3 行执行
$app->get,但未定义 $app。 -
$app 它总是在 index.php 中定义,奇怪的是当我手动执行 require 它的工作时。当它是动态的时候不是。手动 = 已定义 $app 动态 = 未定义 $app
-
@Laurent 我做了一些测试,但问题不在框架中,尽管现在我认为它是 'in' php, fml.