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?
 
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
 
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Jorge BatresAuthor Commented:
Thank you, here is the message.php file
Message.php
0
 
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
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.