Jump to content

why is it fashion to have class properties start with $_xxxx isnt that bad?


alexweber15

Recommended Posts

as in bad practice?

 

I'm reading "Pro PHP Patterns Frameworks Testing and More" from Apress and the author constantly does that throughout the examples and I've seen it a bit around the forums in some examples...

 

Wasn't it considered bad practice to do that???

Because of superglobals and such?  I realize if you can restrain yourself from naming a property "GET, POST or SERVER" (and so on) then you probably wont have a problem but I'm just surprised at the popularity that using underscores to prefix property names has got :)

Link to comment
Share on other sites

Not at all... in 'good practise,' you should have very few variables actually sitting in the global name space, and the chances of them colliding with PHP predefined is extremely low.

 

Usually I see $_varname being used in an object, which should eliminate the possibility of collisions.

 

In the global space, you should use $_prefix_varname.

Link to comment
Share on other sites

Not at all... in 'good practise,' you should have very few variables actually sitting in the global name space, and the chances of them colliding with PHP predefined is extremely low.

 

Usually I see $_varname being used in an object, which should eliminate the possibility of collisions.

 

In the global space, you should use $_prefix_varname.

 

wait so what you're saying is that when you're told to avoid using underscored to prefix variable names it only applies to the global namespace?  still don't see the point of using that particular prefix when theres so many other possibilities like just, god forbid, naming variables according to what they store  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.