OOP Programming Beginner - How do I make this class work?

I'm strating at the beginning and trying to get my brain around OOP. I've got an "OOP for Dummies" in front of me and going through it one exercise at a time.

There's one example that they use and while they use it to illustrate the scaffolding of a class, they don't show how it would actually be used to generate a message, and I want to figure that out.

Here's my class:

class MessageHandler {
      private $message;
      function _construct($message)
            $this->message = $message;
      function displayMessage()
      echo $this->message."/n";

In my HTML, I start by instantiating the class...

$the_message = new MessageHandler;

...and then, that's where it seems to stop.

If I wanted to say "Welcome to the wonderful world of OOP!" how would I do that using my class?
brucegustPHP DeveloperAsked:
Who is Participating?
Ray PaseurConnect With a Mentor Commented:
$thing = new MessageHandler('wELCOME...');
Ray PaseurCommented:
Darn it, Caps Lock.  The most useless key on the keyboard.  But that aside, the example is still structurally correct.

However I would check the date and quality of the learning resource you're using.  In PHP OOP, you can and should designate the visibility of the methods (methods == functions).

Our colleague gr8gonzo has these articles to help you get going:


brucegustPHP DeveloperAuthor Commented:
Thanks, Ray!
Ray PaseurCommented:
Glad to help.  You'll have more OOP questions, I'm sure.  We will be here! ~Ray
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.