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 8673943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:35:00+00:00 2026-06-12T19:35:00+00:00

I am very beginner to OOP and now I am trying to write some

  • 0

I am very beginner to OOP and now I am trying to write some PHP class to connect with FTP server.

class ftpConnect {
  private $server;
  private $user;
  private $password;

  private $connection_id;
  private $connection_correct = false;

  public function __construct($server, $user = "anonymous", $password = "anonymous@mail.com") {

    $this->server   = $server;
    $this->user     = $user;
    $this->password = $password;

    $this->connection_id      = ftp_connect($this->server);
    $this->connection_correct = ftp_login($this->connection_id, $this->user, $this->password);

    if ( (!$this->connection_id) || (!$this->connection_correct) ){
        echo "Error! Couldn't connect to $this->server";
        var_dump($this->connection_id);
        var_dump($this->connection_correct);
        return false;
    } else {
        echo "Successfully connected to $this->server, user: $this->user";
        $this->connection_correct = true;
        return true;
    }
  }
}

I reckon that body of the class is insignificant at the moment.

Main issue is that I have some problems with understanding OOP idea.

I wanted to add sending emails every time, when the code is run. I have downloaded PHPMailer Class and extended my class with it:

class ftpConnect extends PHPMailer {...}

I have added some variables and methods and everything works as expected to that point.

I thought: why not to add storing everything in database. Everytime user runs above code, proper information should be stored in database.

I could edit my ftpConnect class and add database connecting to the constructor, and some other methods to updating tables. But database connecting and all that stuff could be used by other classes in the future, so it definitely should be implemented in seperate class.
But my “main” ftpConnect class already extends one class and could not extend not a single one more.

I have no idea how can I resolve this problem. Maybe my ftpConnect class is to complex and I should somehow divide it into couple smaller classes?
Any help is much appreciated.

  • 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-12T19:35:01+00:00Added an answer on June 12, 2026 at 7:35 pm

    For starters I think you have a design flaw in your class. Your constructor is doing work. That’s not what a constructor should do in proper OOP. Your constructor should just set the properties and you should have a separate method connect().

    Second ftpConnect should never ever extend PHPMailer. They are two totally different things. Read about the Liskov substitution principle it is part of the SOLID principles.

    If your class needs to do something with a database or needs to send mails you need to inject those instances into your class instead of extending them. This is called dependency injection and this will make it easy to do unit tests later, because you can easily use a mock mailer class or a mock database class.

    If you want to send mails, have database access and use FTP you would need at least 3 different (separated) classes (probably even more to do some mapping for the db etc). Basically every class should have one responsibility and one only. This is called the single responsibility principle.

    For some general references see:

    • Guide: Writing Testable Code
    • Google Clean Code Talks
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

very beginner question. I am using Rails 3's query interface as shown: class User
I'm very beginner in Flash. I'm trying to use document class only. I created
I am a very beginner to Java, recently trying to use some existing libraries
I'm very new to Objective-C, and am having some beginner issues. I have an
Here's my background: Decent experience with PHP/MySql. Beginner's experience with OOP Why I want
I am only a very beginner user of git and have a C# Visual
I am very beginner in SQL Server 2005 and I am learning it from
Very beginner level question. Trying to learn JSON and having trouble with getting proper
I am very beginner to Javascript. Just trying to learn modal dialog but encounter
I'm a very beginner in python and django. However I'm trying to create a

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.