Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:44:20+00:00 2026-06-09T20:44:20+00:00

Like: public $foo = null, $bar = 10; protected $_stuff = null, $_moreStuff =

  • 0

Like:

public
  $foo        = null,
  $bar        = 10;

protected

  $_stuff     = null,
  $_moreStuff = 5;

A lot of people seem to do this. Why?

Isn’t this inconsistent naming (like some PHP functions are :))?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:44:22+00:00Added an answer on June 9, 2026 at 8:44 pm

    It really comes down to one thing: personal preference.

    I, personally, am also one who uses that naming convention. Prefixing anything that is protected or private with an underscore, be it a variable or a function, lets myself and any other programmer who I regularly work with know that that variable is global and will not be accessible outside of the current class/context.

    An example that helps clarify the use-case would be with class methods:

    class Example {
        public function firstFunction() {
            // do stuff
        }
    
        protected function _secondFunction() {
            // do more stuff
        }
    }
    

    When I’m writing code that uses the class Example, or working inside of the class itself, if I see _secondFunction() I will immediately know that it’s not a public function because of the starting _ and thereby not accessible outside of the class; no need to go and find the actual function declaration and see the modifier. On the flip side, I will know that firstFunction() is public because it doesn’t begin with one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*
Assume I have a class like this: public class Foo { public Bar RequiredProperty
I have a class like this public class foo { private void getThread() {
I'm using MVC3 and I have a model like this: public class Foo {
I imagine to use XML serialization like this: class Foo { public Foo (string
My code currently looks like this: private Foo myFoo; public Foo CurrentFoo { get
I would like to do something like this: abstract class Foo { public function
I saw a java function that looked something like this- public static<T> foo() {...}
If I have a class, Foo, looking like this... class Foo { public string
i declared classes like this: class Foo{ public function __construct(){ echo 'Foo was created!';}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.