Welcome Guest, Not a member yet? Register   Sign In
public and private functions?
#1

[eluser]Iwasignited[/eluser]
Hello everyone.
I got a question.
I am following this tutorial http://www.phpandstuff.com/articles/code...user-login
I want to ask about the point of using public and private function here
because I followed Jeffrey Way's screencast before and dont see anything like that.
Looking forward to hearing from you soon.
Thanks.

P/s: sorry for my English
#2

[eluser]kgill[/eluser]
I haven't read the tutorial but the point of private functions is for control. Think of it like this, if you've got a car, the steering wheel is the public interface to the steering mechanism; you leave that visible to everyone because that's how you want them to interact with the car. You hide all the gears and pumps away because while you could theoretically steer the car by pulling and twisting things that's not how it was meant to be used. Same concept as a programmer, you define public & private functions to ensure your code is only used in a manner you intended. It also ensures that you're able to rewrite how the code works within your class - as long as the input & output of the public functions remains the same you won't need to rewrite any other code that uses that class because the public interface didn't change.
#3

[eluser]n0xie[/eluser]
http://php.net/manual/en/language.oop5.visibility.php
#4

[eluser]Iwasignited[/eluser]
Thank you guys. If we do not have any of them, it will be public by default right?
#5

[eluser]n0xie[/eluser]
yes
#6

[eluser]GSV Sleeper Service[/eluser]
code igniter seems to ignore the private and public keywords, the only surefire way of making a controller method private is to start it's name with an underscore.
#7

[eluser]danmontgomery[/eluser]
Codeigniter doesn't use public and private keywords because they aren't supported in PHP 4. Prepending a function name with an underscore does not make it private, it's only an indicator used in PHP 4 to denote that a function should be considered private.
#8

[eluser]Iwasignited[/eluser]
If they are not supported, the use of private and public in this tutorial is useless?
#9

[eluser]danmontgomery[/eluser]
[quote author="Iwasignited" date="1268688006"]If they are not supported, the use of private and public in this tutorial is useless?[/quote]

If you never intend on using any version of PHP after 4, and never intend on using any other OO language, then I suppose you don't need to bother.




Theme © iAndrew 2016 - Forum software by © MyBB