我这个函数是写在这个文件的后面的、运行这页代码的时候会提示Fatal error: Call to undefined function page() in E:\php\readir.php on line 52函数必须在调用代码之前被声明么?为什么我看到另外一断代码是可以将声明函数放在调用代码之后的呢?$patch='./dbbak/';
if ($handle = opendir($patch.$_GET['id'])) 
       { 
        echo '<table id="tb1">
        <th width="80px">客户编号</th>
        <th width="200px">文件名</th>
        <th width="80px">文件大小</th>
        <th width="200px;">上传时间</th>
        <th width="30px">下载</th>
        </table>';
      }
      $f = array("1","2","3","4","5","6","7","8","9","10","11");
//      $f =  glob($patch.$_GET['id'].'/*');
      
      if (isset($_GET['page']))
      {
       $page = $_GET['page'];
       }
      else
      {
       $page = 1;
       }
       
 $r = page($f,2,$page);
 foreach($r["source"] as $value){
 echo $value.'
      <br/>
      '.$r["page"];
 }
 
 
 
  function page($f,$pagesize,$current)
{
$_return = array();
$total = ceil(count($f)/$pagesize);
$prev = (($current-1)<=0 ? "1":($current-1));
$next =($current+1>=$total ? $total:$current+1);
$current =($current>($total) ? ($total):$current);
$start = ($current-1)*$pagesize;

   for($i=$start;$i<($start+$pagesize);$i++)
   {
    array_push($_return,$f[$i]);
    }
    $pagearr["source"]=$_return;
    $pagearr["page"]="<a href=\"?acticon=barfilelist&page=1\">first</a> <a href=\"?acticon=barfilelist&page={$prev}\">prev</a> <a href=\"?acticon=barfilelist&page={$next}\">next</a> <a href=\"?acticon=barfilelist&page={$total}\">end</a>";
    return $pagearr;
}/*
     if ($f!="." && $f!="..")
     {   
     $t = array_map('filemtime',$f);
     $s = array_map('filesize',$f);
     array_multisort($t,SORT_DESC,$f);
           }
     for($i=0;$i<count($f);$i++)
        {
  
       echo '<table id="tb2">
            <td width="80px">'.$_GET['id'].'</td>
            <td width="200px">'.substr($f[$i],19).'</td>
            <td width="80px">'.intval(($s[$i])/(1024)).'KB</td>
            <td width="200px">'.date('Y-m-d H:s',$t[$i]).'</td>
            <td width="30px"><a href="http://localhost/'.$f[$i].'"><img alt="点击下载" align="center" style="border:0;" src="./image/download2.gif" /></a></td>
         </table>'; 
        }  */
 closedir($handle);

解决方案 »

  1.   

    哪一行是第52行,贴出来的代码完整吗?
    //测试没问题
    page('test');
    function page($str) { echo $str; }
      

  2.   

    函数声明在哪都OK 必须引用或者在同个文件.
    line 52 我不知道是哪个地方,因为你用的开发工具可能不一样代码里唯一用到page的地方是
    $r = page($f,2,$page);
    没有发现不妥的地方
      

  3.   

    是在同一个文件里面、但是这个文件中有几个switch case、函数和调用函数都位于同一个case里面、我只要把调用的语句放到声明函数之后就不会报这个错误了,晕翻了额
      

  4.   

    那是因为你函数没有声明好。为什么要把函数声明放在switch里面去呢?在外面声明多好啊。。然后在switch...case里根据条件调用函数。
      

  5.   

    感谢大家、我非常无奈的将函数放到switch外面去声明了。