10 Comments

  1. Ryan Hellyer

    This is an awesome reference! Thanks for reporting it Sarah, and thanks to my former colleagues at 10up for sharing it :)

    I don’t understand this bit … ” Anything intended to be private should actually be specified as protected. There should be no private fields or properties without well-documented and agreed-upon rationale.”. Does anyone reading this understand the logic behind that?

    Report

  2. Ronald Huereca

    I’m guessing, but it may mean that classes that extend a parent class can have access to methods and class variables that are private, but not protected.

    http://stackoverflow.com/questions/4361553/php-public-private-protected

    Report

    • Ronald Huereca

      Sorry, I spoke to soon. Protected methods and vars are available in classes that inherit the parent class, but not private methods and vars.

      Report

      • Ryan Hellyer

        Yep, I get that. I’m just not understanding why that is a reason not to make stuff private. Sometimes I don’t want people messing with stuff, so making it private makes sense then IMO.

        Report

        • Dave Ross (@csixty4)

          Some things do truly need to be private, and there’s nothing wrong with making them so as long as you document the reasoning behind it. That way, people reading your code can understand even if they don’t agree with you.

          What we’re trying to prevent is classes that are overly-stingy with access to their members, where child classes can’t even display data because they can’t access it, for example. It’s hard to know everything other programmers will want to do ahead of time, and there’s no sense making things difficult for them.

          Report

        • Zamoose

          Not “never”, just “only with a really good reason that your colleagues agree with”. *grin*

          Report

          • Ryan Hellyer

            I think I’ve figured it out. By making things private, it prevents others from extending their functionality, which could be bad in some situations. But the purpose of using a private method is to STOP people from extending the functionality, so as long as you know what they’re there for, then that shouldn’t be a problem. So I guess what that text is meaning, is that you should only make things private if you know what the ramifications of doing that are.

            Report

  3. Rhys

    As somebody who generally works on his own, with very little formal training, I love resources like this. Bravo 10up :)

    Report

  4. CodeProKid

    This is awesome! Great to see companies this big being so transparent. Very helpful for the community.

    Report

Comments are closed.

%d bloggers like this: