Forum Moderators: coopster

Message Too Old, No Replies

Error message 'non-static method' need a pointer

class method error message

         

Matthew1980

7:54 pm on Apr 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people of the forum!

I have an error message that I have absolutely no idea how to correct:-

Non-static method Captcha::Validate() should not be called statically

I have only had this come up in the last few days, the error has always been there, but since I changed over to E_STRICT on error_reporting() I have only just noticed it tonight.

I'm not particularly well versed on class's as I am still learning them, so could anyone point me in the direction I should be going.

I have googled this but as yet nothing concrete,

Cheers,
MRb

eelixduppy

8:11 pm on Apr 29, 2010 (gmt 0)



In the class Captcha, you are calling a method Validate(). Except since the method was not declared as static, this method only exists as part of an instance of the Captcha class. So for example, you are going something like this:

Captcha::Validate();


When you should be doing something like:

$CaptchaInstance->Validate();

Matthew1980

8:23 pm on Apr 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi again eelixduppy,

Thanks for the explanation :) I have now defined the function in the class as:-

static function Validate(){
//function stuff
}

Problem solved!

I think I am going to have to start learning classes properly, I just can't seem to grasp the basics..

Cheers,
MRb

eelixduppy

3:57 pm on Apr 30, 2010 (gmt 0)



OOP takes some time to get your head around. Once you get it everything else just falls into place. As always, read the documentation alongside of any other reading material you might find: [php.net...]

Best of luck learning! :)

dreamcatcher

8:40 am on May 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, good luck. And remember that some PHP5 class options will not run under PHP4. Classes had a major re-vamp in 5.

dc