Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:07:23+00:00 2026-06-10T11:07:23+00:00

Basically I created this script that check if a file exists and then creates

  • 0

Basically I created this script that check if a file exists and then creates it.
It worked great before when I had a non OOP version of it.

Now I modified it to become OOP and somehow it doesn’t work and I get the error in Apache PHP Fatal error: Call to undefined function createFile() in C:\Program Files (x86)\Zend\Apache2\htdocs\Proj11\1.php on line 66

I highlighted where line 66 is with the line //// THE ERROR LINE BELOW

Whats wrong with it??? thx

<?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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:07:24+00:00Added an answer on June 10, 2026 at 11:07 am

    createFile() is a method defined in the class, and must be called inside the class as $this->createFile():

    if ($this->createFile()) {...}
    

    I have not looked over your code thoroughly yet, but you may have omitted $this-> on other method calls as well.

    I’ll point out also that since there doesn’t appear to be any circumstance in which createFile() returns anything other than TRUE, there’s no real need for the if () {} block; the else case will never be reachable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a native Android app that basically hosts a webView control. That webView
Basically, I have created a custom control that uses an UpdatePanel, and as I
Basically, I have a model where I've created a superclass that many other classes
Basically, I am using Wireshark looking at captures that have been created previously. How
I'm basically trying to play with recursions and created a small program that finds
I have created a script that reads from a CSV (or other dataset, but
I have a bash script that I am run to check to see if
I have this piece of code that basically checks if one or more files
I created an upload script in node.js using express/formidable. It basically works, but I
I am currently writing a script that will basically ‘install’ a codeigniter installation automatically.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.