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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:21:22+00:00 2026-05-19T02:21:22+00:00

I wrote these two classes that simple encrypt and decrypt strings: Encode.php class Encode

  • 0

I wrote these two classes that simple encrypt and decrypt strings:

Encode.php

    class Encode {
        protected funcion do_encode($string) { .. }
    }


Decode.php

    class Decode {
        protected funcion do_decode($string) { .. }
    }

What I would like to do is:

Encrypt.php

    class Encrypt extends Encode, Decode {
        protected $stuff_for_parents;

        function __construct($configs) {
            $this->stuff_for_parents = $configs['SomeConf'];
        }

        public function encode($string) { $this->do_encode($string); }
        public function decode($string) { $this->do_decode($string); }
    }

But we cannot include more than one class, so: fail.
Now my questions are:

  1. Is it a design problem? Cause this scenario doesn’t look weird to me, does it?
  2. Is there another way to have one object that uses both the functions in the different classes? Sort of $encrypt->encode($str); $encrypt->decode($str);
  • 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-05-19T02:21:23+00:00Added an answer on May 19, 2026 at 2:21 am

    If you want Encode and Decode to be separate classes, you can create instances of them within Encrypt. For example:

    <?
    class Encrypt {
      private $encoder;
      private $decoder;
      public function __construct() {
        $this->encoder = new Encode();
        $this->decoder = new Decode();
      }
      public function encode($string) {
        return $this->encoder->encode($string);
      }
      public function decode($string) {
        return $this->decoder->decode($string);
      }
    }
    ?>
    

    In that example Encode and Decode must be concrete classes. But you might want to consider using interfaces instead. Interfaces are useful if you think you might need to use different types of Encode and Decode objects, in different situations. For example, maybe you have a TripleDESEncode class and a BlowfishEncode class. They can both implement a common interface, like this:

    <?
    interface IEncode {
      public function encode($string);
    }
    class TripleDESEncode implements IEncode {
      public function encode($string) {...}
    }
    class BlowfishEncode implements IEncode {
      public function encode($string) {...}
    }
    ?>
    

    In that case, you may want to create the particular instances you want to use first, and then pass them into the constructor of Encrypt. This is called dependency injection:

    <?
    class Encrypt {
      public function __construct(IEncode $encoder, IDecode $decoder) {
        $this->encoder = $encoder;
        $this->decoder = $decoder;
      }
      ...
    }
    
    $myEncrypt = new Encrypt(new BlowfishEncode(), new BlowfishDecode());
    echo $myEncrypt->encode('test');
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have two classes that have the exact same public accessors (and many of
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I am trying to understand type members in Scala. I wrote a simple example
We have a simple Webapp running on two Tomcat instances behind Apache (a Tomcat
I want to be able to have two projects, one that contains production code
I wrote two different custom Ant tasks. They are trying to share data through
I am porting some queries from Access to T-SQL and those who wrote the
Recently an application I wrote started not working on Internet Explorer. There has been
Lets say I need to write several functions processing some data. These functions are
Is there a way to write an enumeration that can be extended. I have

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.