脚本被修改为OOP,现在它不起作用

Jon*_*rft 1 php

基本上我创建了这个脚本,检查文件是否存在然后创建它.在我有非OOP版本之前,它工作得很好.

现在我修改它成为OOP,不知何故它不起作用我在Apache PHP中出现错误致命错误:在C:\ Program Files(x86)\ Zend\Apache2\htdocs\Proj11 \中调用未定义的函数createFile()第66行.php

我突出显示了第66行与该行的关系 //// THE ERROR LINE BELOW

它出什么问题了???谢谢

<?php 
//DB Config File



$phase = $_GET['phase'];

if(empty ($phase)){
    $phase = new phase1();
    $phase->start();
    } elseif ($phase = 1) {
        $phase = new phase2();
    $phase->stepFunction();
        };

class phase1 {

    function __construct () {
        $dbFile = 'dbconfig.php';
        $step = 0;
        $username = $_GET['username'];
        $password = $_GET['password'];
        $server = $_GET['server'];
        $dbName = $_GET['dbName'];

        $this->step = $step;
        $this->dbFile = $dbFile;
        $this->username = $username;
        $this->password = $password;
        $this->server = $server;
        $this->dbName = $dbName;

        $db = new PDO ('mysql:host=' .$server.';dbname='.$this->dbName,$this->username,$this->password);

        $this->db = $db;
        }


public function createFile () {
        //Creates File and populates it.
        $fOpen = fopen($this->dbFile, 'w');
            $fString .= "<?php\n";
            $fString .= "// Database Constants\n";
            $fString .= "\$DB_SERVER =" . "\"" . $this->server . "\";\n";
            $fString .= "\$DB_USER =" . "\"" . $this->username . "\";\n";
            $fString .= "\$DB_PASS =" . "\"" . $this->password . "\";\n";
            $fString .= "\$DB_NAME =". "\"" . $this->dbName . "\";\n";
            $fString .= "?>";

        fwrite($fOpen, $fString);
        fclose($fOpen);

    return true;
}   


public function start (){

try {

if ($this->db) { //if succesful at connecting to the DB

if (file_exists($this->dbFile)){
    if (is_readable($this->dbFile) && is_writable($this->dbFile)){ 

        //Creates File, populates it and redirects the user

  //////////////////////////
  //// THE ERROR LINE BELOW
  //////////////////////////

    if (createFile()) { 

        $phase = new phase2();
        $phase->stepFunction($this->step);
         exit ();
            }


        } else { 

        echo "The file {$dbFile} cannot be accessed. Please configure the file manualy or grant Write and Read permission.";  }

    } else {

        //Creates File, populates it and redirects the user

    if (createFile()) {


        $phase = new phase2();
        $phase->stepFunction($this->step);
         exit ();
            }

        }


}

} catch (PDOException $e) { //Catchs error if can't connect to the db.
    echo  'Connection failed: ' . $e->getMessage();
}

}
    } // en class Phase 1
Run Code Online (Sandbox Code Playgroud)

Mic*_*ski 8

createFile()是类中定义的方法,必须在类中调用$this->createFile():

if ($this->createFile()) {...}
Run Code Online (Sandbox Code Playgroud)

我还没有彻底查看你的代码,但你也可能$this->在其他方法调用上省略了.

我还要指出,由于似乎没有任何情况可以createFile()返回除此之外的任何东西TRUE,因此不需要if () {}块; 的else情况下,将永远不会到达.