Forum Moderators: coopster

Message Too Old, No Replies

What does protect/public/ modifiers mean?

         

Sarah Atkinson

3:52 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



I get an (!)saying something aboult please use protected/public modifiers
what does this mean?

Sarah

jatar_k

4:16 pm on Jun 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what are you trying to do when you get this?

Sarah Atkinson

4:23 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



it's in a class that handles the sessions

gliff

4:40 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



Are you using PHP 5?

PHP 5 expanded and changed the way object oriented code works, including allowing you to declare functions as public, private or protected. Inside classes, functions should be declared something like

public function afunctionname(){
}
private function anotherfunctionname(){
}
private function protectedfunctionname(){
}

For the sake of backwards compatibility, if the public/private/protected/afewothers keyword isn't there, (as is always the case with code written for PHP 4), PHP 5 assumes the function is public.

It sounds like you have a high warning level set. You can lower this warning level to stop these messages from showing up, or you could irritate object oriented programmers everywhere and just add the word "public" in front of all your class functions.

If you want to learn what all these mean, I recommend the O'Reilly "Upgrading to PHP 5" book as a good primer.

Sarah Atkinson

4:46 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



I can just see all the problems croping up with this small thing i didn't consider. this code it PHP4... I am running 5 on my system (just set IIS and all the rest of the 'stuff' up) when I did that I just took the newest version without realy thinking aboult it. however I belive my remote server(the one I'm writing code for) is still running PHP4.

So what happens when you put PHP5 code on a server running php4?

gliff

5:01 pm on Jun 21, 2005 (gmt 0)

10+ Year Member




So what happens when you put PHP5 code on a server running php4?

If you're really really really really really lucky, it will work.

You won't be that lucky.

Get a PHP 4 testing/development system.

coopster

10:21 am on Jun 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Or modify the code to satisfy PHP5 requirements ;)

To suppress those class warning errors you simply need to tone down the error_reporting [php.net] level from E_STRICT to E_ALL or if you have reviewed the code in the class and are comfortable with it, turn errors off altogether for that script/class. However, and this would be my recommendation, if you are going to take the time to review the class you may as well modify the Visibility [php.net] to get rid of your errors.