views:

88

answers:

5

can any one please let me know the global declaration of php variables..i have seen one among the site like..

for integer start with i, eg: $iItemId
for array start with a, eg: $aItemIds
for string start with s, eg: $sItemName
+3  A: 

See:

PHP Coding Standards

Sarfraz
hi thanks for ur reply...
VAC-Prabhu
@PHP-Prabhu: You are welcome :)
Sarfraz
You are supposed to accept his answer. Actually you are supposed to accept answers to most of your questions.
Lo'oris
Lo'oris you suggest him to accept answer and on the other hand you criticize and vote down using the same conventions, first example on the link is a "$errorNumber" var... strange
Benoit
So what? He clearly considers this his accepted answer, so he should accept it. The fact that I might not agree is irrelevant. I also upvoted this one, FYI.
Lo'oris
A: 

I do not use such conventions, and it is rare to see this in php, it's more a VB thing I guess...

If you give good names to variable, their types will appear. For instance, the not so strict conventions I use vor variable naming :

  • $i, $j, $k, $l, etc. and all single letters variables are integers used as counters
  • $messageRow => it's a DB result instance
  • $messageCollection => it's results collection
  • $messageRows => array , Using plural denotes multiple items
  • $messageTitle => it's a string
  • $messageVisible or $isMessageVisible => it's a boolean

In fact everithing now tends to be object, except array and strings, and good naming with good comment and/or visible typecast (mainly on methods arguments, or specific use) makes variables more readable code and guessing types is easier than having a whole bunch of $oThis and $oThat

Benoit
-1 don't encourage such an unreadable behaviour, please. Let's leave the capmixing to barbaric languages like java.
Lo'oris
The question was about using typing hint in variable name, not using cap or underscore to separate words in those names.It's a matter of choice, why vote down on this ! I work with Symfony framework everyday, and it uses this convention, it's better not mixing conventions don't you think ? I use underscore for string identifiers, like array keys, config names, etc.Also, it's easier to type a cap than getting the underscore key, at least on my AZERTY keyboards
Benoit
Also, I don't think Java should be treated as a barbaric language...
Benoit
How easy can you write it is irrilevant confronted to how easy can anyone *read* it. CapMixingIsJustUnreadable, face it.
Lo'oris
its perfectly readable imho.... I used a lot of underscore variables when I was working on php4 procedural projects, for me both are as readable, way more than variable like $idonthaveanywordseparator. The point is the convention to use depends more on the project convention and people you work with than you own preference or supposed readability.
Benoit
A: 

God, no!

Avoid like hell idiotic names LikeThisOne.

Never ever use caps in a variable name, unless it's ALLCAPS.

Use underscore to separate words if you need to.

Lo'oris
for example Zend coding standards says "use caps". in many different languages its a standard to use caps.
choise
Agreed. `$myvar` could be `$my_var` or `global $MYGLOBAL` perhaps, or just plain old `global $my_little_global`.I've no real issue against camelcasing, but I'd only really do it in Class names and the like
DavidYell
The question was about using typing hint in variable name, not using cap or underscore to separate words in those names.
Benoit
That's a pretty bad advice. These "idiotic" names are used in Zend Framework, Symfony, CakePHP and many other frameworks and libraries.
Alexander Konstantinov
And the suck anyway.
Lo'oris
the caps and small setters will always to identify when the variable declare lengthy
VAC-Prabhu
"use caps" or "camelized" is more of a Java thing, not php. Method / function names should always be lowercase with underscores in php, it's far much easier to read, so why not variables too ?
Kemo
A: 

What you're describing is called Hungarian Notation, nobody seems to have mentioned that yet.

In answer to your question, I would suggest using whatever style you're most comfortable with. As long as it's consistent and readable it doesn't really matter. That said, hungarian notation isn't the most readable style...

Alex
+1  A: 

Use the style you are comfortable with.

But also take into account the frameworks you are using. If you use mostly the Zend Framework choosing a style different to their style may lead to "visually confusing" code, since the style switches.

ZeissS