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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:03:29+00:00 2026-05-30T05:03:29+00:00

I read this entire post . It describes what a wrapper class is to

  • 0

I read this entire post. It describes what a wrapper class is to other experienced programmers, but not to a newbie like me.

I understand PHP syntax, the object-oriented concept, but have not written my own application in object-oriented code yet. I am beyond confused when trying to figure out what exactly a wrapper class is. I don’t understand the technical jargon.

I hope someone answers with a beautiful detailed child-like description that is easy to understand for someone that understands the basics of object oriented program and has read through pretty much the entire php.net language reference, but has no actual object oriented programming experience. No applications written yet.

  • 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-30T05:03:31+00:00Added an answer on May 30, 2026 at 5:03 am

    Since the explanations on the question you linked to are quite extensive, I will not go an redefine it for you again. Instead, I will try to show you via an example of injection.

    class Logger {
    
        private $__logger;
    
        public function __construct($logger) {
            $class = $logger . "Logger";
            $this->$__logger = new $class();
        }
    
        public function write($message) {
            $this->$__logger->write($message);
        }
    }
    

    So, above you have a class Logger that you may be using to log information somewhere. We don’t really care how it does it, we just know it does.

    Now, we have a couple of different logging possibilities…

    class DBLogger {
    
        public function write($message) {
            // Connect to the database and 
            // INSERT $message
        }
    }
    
    class FileLogger {
    
        public function write($message) {
            // open a file and
            // fwrite $message
        }
    }
    
    class EMailLogger {
    
        public function write($message) {
            // open an smtp connection and 
            // send $message
        }
     }
    

    Now, when we use our logger, we do it by doing any of the following:

    $logger = new Logger("DB");
    $logger = new Logger("EMail");
    $logger = new Logger("File");
    

    We always interact with $logger in the same way (ie. we call write($message)). The wrapper instance Logger wraps the actual logging class and calls its methods on our behalf.

    A more common use of the above type of code would be when using configuration files to determine what your logger is. For example, consider the case where you want to have your logging sent to a file. You might have a config that looks like this:

    $logging = array( 
                   'type' => 'file',
                   'types' => array(
                       'file' => array(
                           'path' => '/var/log'
                           'name' => 'app_errors.log'
                        ),
                        'email' => array(
                           'to' => 'webmaster@domain.com',
                           'from' => 'error_logger@domain.com',
                           'subject' => 'Major fail sauce'
                        ),
                        'db' => array(
                            'table' => 'errors',
                            'field' => 'error_message'
                        )
                    )
    );
    

    And your adapted classes might look like:

    class FileLogger {
    
        public function __construct() {
            // we assume the following line returns the config above.  
            $this->config = Config::get_config("logger");
        }
    
        public function write($message) {
            $fh = fopen($this->config->path . '/' . $this->config->file);
            fwrite($fh, $message . "\n");
            fclose($fh);
        }
    }
    

    We would do the same for the other adapted classes. Then, with a little modification to the main Wrapper Logger, we could create the correct wrapped instance by using the configuration data and base it on the type that is defined in the config. Once you have something like that in place, switching over to logging via email is as easy as changing the type in the config.

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

Sidebar

Related Questions

EDIT2 Looks like I can't read properly, disregard this post, I will try to
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read this post last night, and I noticed it was from 2006. I
Hi I read a few post on this topic, lets say I want to
I've read an blog post(at this moment I can't find the link) where the
Since this is a huge post here is a short summary (please read the
I read Rick Strahl's post about DataContext lifetime management, and some of the other
<div id=msg_container> <span> Is this helpful ? </span> <span class=feedback> <a title=like> Yes </a>
I read this answer and its comments and I'm curious: Are there any reasons
I read This article and i found it interesting. To sum it up for

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.