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 :)

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.