TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-09-2008, 08:19 PM   #1 (permalink)
The Contributor
 
Izym's Avatar
 
Join Date: Sep 2007
Posts: 32
Thanks: 0
Izym is on a distinguished road
Default 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.

Last edited by Izym : 12-09-2008 at 08:46 PM.
Izym is offline  
Reply With Quote
Old 12-09-2008, 08:44 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Old 12-09-2008, 09:14 PM   #3 (permalink)
The Contributor
 
Join Date: Mar 2008
Posts: 31
Thanks: 1
masfenix is on a distinguished road
Default

Most of my private variables start with just underscore. And then all of my properties contain the proper case for that variable.

Code:
private string _name;

public string Name{ get { return _name; } set { _name = value }};
masfenix is offline  
Reply With Quote
Old 12-09-2008, 11:13 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-10-2008, 09:10 PM   #5 (permalink)
The Contributor
 
Izym's Avatar
 
Join Date: Sep 2007
Posts: 32
Thanks: 0
Izym is on a distinguished road
Default

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.
Izym is offline  
Reply With Quote
Old 12-10-2008, 10:03 PM   #6 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default

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.
Killswitch is offline  
Reply With Quote
Old 12-11-2008, 12:13 AM   #7 (permalink)
The Wanderer
 
Join Date: Nov 2008
Location: Plymouth, UK
Posts: 9
Thanks: 0
Measter is on a distinguished road
Default

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.
Measter is offline  
Reply With Quote
Old 12-12-2008, 01:22 AM   #8 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

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 :)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Old 12-12-2008, 01:28 AM   #9 (permalink)
The Contributor
 
Join Date: Mar 2008
Posts: 31
Thanks: 1
masfenix is on a distinguished road
Default

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.
masfenix is offline  
Reply With Quote
Old 02-19-2013, 05:29 AM   #10 (permalink)
The Wanderer
 
Join Date: Feb 2013
Posts: 17
Thanks: 0
Rainman is on a distinguished road
Default

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!
Rainman is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
help me understand short notation. sarmenhb XHTML, HTML, CSS 4 08-14-2008 02:00 PM
Hungarian Notation Wildhoney General 6 11-30-2007 03:18 PM


All times are GMT. The time now is 12:51 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design