PHP Deprecated: Non-static method Message::setMessage() should not be called statically

Hi, I need help with a problem I'm having with a deprecated function warning that I would like to correct:

mod_fcgid: stderr: PHP Deprecated: Non-static method Message::setMessage() should not be called statically in /var/www/vhosts/XXXXX.com/httpdocs/calendar/modules/Core/Page.php on line 340

I have attached the page.php file.

Please help.

Thanks,

Jorge B
Page.php
Jorge BatresAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
We would need to see the message.php file that is included in the file you posted.

Basically the method is saying this

Class Message {
   function setMessage () {
      echo "Do something useful";
   }
}

Open in new window


In page.php the setMessage function is being invoked like this
Message::setMessage()

Open in new window


This means the code is calling the setMessage function on the class itself - not an instantiation of the class. It is throwing a warning because it wants you to declare it like this

Class Message {
   public static function setMessage () {
      echo "Do something useful";
   }
}

Open in new window

0
gr8gonzoConsultantCommented:
It means what it says. You have a class called Message with a regular class method called setMessage. So if you have $XYX that was an instance of your Message class:

$XYZ = new Message();

...then you would call setMessage() on the instance:

$XYZ->setMessage("message here");

Instead, you are trying to call setMessage as if it were a static method on the Message class, which it isn't. It's just a regular method.

If you're not sure what the differences between static and non-static are, check out my article on OOP:
https://www.experts-exchange.com/articles/2631/Advanced-Object-Oriented-Programming-in-PHP.html
0
Jorge BatresAuthor Commented:
Thank you, here is the message.php file
Message.php
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

gr8gonzoConsultantCommented:
So it looks like Messages can be made static. Just add "static" in front of the "function" keyword for each method:

static function setMessage($message)
...
static function getMessages()
...
static function haveMessages()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jorge BatresAuthor Commented:
Thank you gr8gonzo I will give it a try now.

Thanks,

Jorge B.
0
Jorge BatresAuthor Commented:
Thank you so much to both!

Jorge B.
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.