![]() |
Hungarian Notation
Let me first make one thing clear: I love using hungarian notation.
When using hungarian notation in PHP, do you then use the "m_" prefix for class variables? Honestly I don't see the use for this in PHP. Sure, this is useful in languages where you don't use "$this" or "self::", but in PHP you should under any circumstance be aware that it is a class variable. |
I'm not a huge fan of Hungarian notation, but that's entirely personal opinion. Wildhoney has adopted it as a pseudo-standard on TalkPHP and seems to really, really love it. :-)
|
Most of my private variables start with just underscore. And then all of my properties contain the proper case for that variable.
Code:
|
I do love it, as Salathe said. However, I do have exceptions, such as like accessing variables from outside of a class, like they do in Zend, I prefer
$pObject->name to $pObject->szName, although I would prefer to use $pObject->getName().I do use the m_ format, however, for class variables. You're right in that it should be obvious anyway, and I can't think of any examples, but it's merely down to personal preference. It is a member variable, and so it's labelled as one, as well as its prefix for its actual type. Many people when posting code on TalkPHP seem to have adopted the Hungarian Notation style. I am not sure why, hopefully it seems logical to some people and helps them. Other people, such as like Salathe, use it cause many people on TalkPHP seem to, I would assume. |
Indeed it is very helpful, just the thing with m_ since you'd have to be a total noob to not know whether its a class member or not. I do agree with you on the getName() thing, I like it better than just accessing to variable directly.
|
I don't use it too often, mainly because I had no clue it existed or had a special meaning/purpose. I do however in class variables use the _ underscore. Don't know why, just kinda picked up on it. Think it was probably for looking around in Joomla code and seeing how they did this and just liked using it.
|
I don't use the proper Hungarian Notation, but something similer:
iVar contains an integer fVar contains a float sVar contains a string aVar contains an array oVar is an object rVar is some sort of resource(file, directory..) and bVar is a boolean For the couple of classes I've written, private members have a double underscore prefix, then the variable type and name. For example: __sVar. |
I don't use notations at all in PHP, to my eyes it just clutters up my code for no reason. I'm always 100% sure which type my variable caries when I read the code :)
|
That may be true kalle, but to other users who are used to doing to it with a prefix/suffix, it would just be confusing to them.
Guess you cant satisfy them all. |
Welcome to mmoggg website to buy RS Gold, offer a lot, of course, Diablo 3 Gold and Cheap RS Gold, to be purchased at any time, at any time shipment, and Diablo 3 Gold Kaufen look forward to your visit!
|
| All times are GMT. The time now is 12:29 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0