使用include_once时变量超出范围

时间:2017-10-16 03:44:30

标签: php scope

我写了一个自动加载器类。

include_once函数不包含我需要的文件。

Cls.php(路径:CLS /)

<?php 
    class fileup{
     function dup($a){
      $x=strip_tags($a);

       $d=__DIR__."/".$x.".cls.php";
      echo $d; ///storage/emulated/legacy/htdocs/yeni/sinif/ayar.sinif.php
        if(file_exists($d)){
          include_once $d;
        }else{
       die($a." Class not found :(");
       }
     }
    }
 $dup=new fileup();
 spl_autoload_register(array($dup,"dup"));
?>

Theme.cls.php主题类(路径:cls /)

<?php 
   include_once("cls.php");
   $dup->dup("conf"); 
?>

Conf.cls.php站点配置类(路径:cls /)

<?php include_once("cls.php"); $dup->dup("db"); ?>

index.php(路径:/)

<?php 
  include_once("theme.cls.php");
?>

错误详情:

Fatal error: Uncaught Error:
Call to a member function dup() on null in /storage/emulated/legacy/htdocs/yeni/sinif/conf.cls.php:3
Stack trace:
#0 /storage/emulated/legacy/htdocs/yeni/sinif/cls.php(12):
**include_once() #1** 
/storage/emulated/legacy/htdocs/yeni/sinif/theme.cls.php(3):
dup->dup('conf') #2
/storage/emulated/legacy/htdocs/yeni/index.php(2): 
include_once('/storage/emulat...') #3
{main} thrown in /storage/emulated/legacy/htdocs/yeni/sinif/conf.cls.php on line 3

0 个答案:

没有答案