For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > April 2005 > good coding in php









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author good coding in php
Pugi!

2005-02-12, 3:55 pm

Are there any standards about good coding practices in PHP ?
Do you use capitals or not ? imagecreate or ImageCreate
How do you name variables ? $arrColorBlack, $black, $strFirstName,
$firstname, $intYear, $year, .....
How do you name your own functions ? drawLines(), setName, printHeading,
heading, createaddress, ......
How about exception or error handling?
Since I am learning PHP I might as well learn it good.

thanx,

Pugi!


J.O. Aho

2005-02-12, 3:55 pm

Pugi! wrote:
> Are there any standards about good coding practices in PHP ?


IMHO

never have a blank between function name and the parenthesis, eg
yes: sort($myarray);
no.: sort ($myarray);


Use lower cases on the function names that are part of the php.
eg: sort()

Use a capital character in the functions you create yourself.
eg: sortArray()


Give variables a describing name
yes: $pageIndex
no.: $i


Use brackets the same way all the time
eg:
if(true) {
echo "true";
} else {
echo "false";
}

or:
if(true)
{
echo "true";
}
else
{
echo "false";
}

But don't mix the methods.
What is most important is that you are consistent whit how you write your
code. Don't forget to use comments, you will need it when you read your code
an year later, or if someone else uses your code. Better to have to many
comments thant to few (if you want to see bad opensource commenting, take a
look at the Gnome2 code).


//Aho
Janwillem Borleffs

2005-02-12, 3:55 pm


"J.O. Aho" <user@example.net> schreef in bericht
news:376nghF582al3U1@individual.net...
> never have a blank between function name and the parenthesis, eg
> yes: sort($myarray);
> no.: sort ($myarray);


Agreed

> Use brackets the same way all the time
> eg:
> if(true) {
> echo "true";
> } else {
> echo "false";
> }
>


Also agreed, but with the remark that I would suggest to put a singe white
space character between "if" and the parenthesis to improve readability:

if (true) {
...
}

The same suggestion would apply to for/foreach/switch.


JW



News Me

2005-02-12, 3:55 pm

Pugi! wrote:
> Are there any standards about good coding practices in PHP ?
> Do you use capitals or not ? imagecreate or ImageCreate
> How do you name variables ? $arrColorBlack, $black, $strFirstName,
> $firstname, $intYear, $year, .....
> How do you name your own functions ? drawLines(), setName, printHeading,
> heading, createaddress, ......
> How about exception or error handling?
> Since I am learning PHP I might as well learn it good.
>
> thanx,
>
> Pugi!
>
>


The PHP Extensions and Application Library (PEAR) has a coding standards
page in their manual:

http://pear.php.net/manual/en/standards.php

--
convert UPPERCASE NUMBER to a numeral to reply
Michael Vilain

2005-02-12, 3:55 pm

In article <420e18ce$0$44066$5fc3050@dreader2.news.tiscali.nl>,
"Pugi!" <reply@group> wrote:

> Are there any standards about good coding practices in PHP ?
> Do you use capitals or not ? imagecreate or ImageCreate
> How do you name variables ? $arrColorBlack, $black, $strFirstName,
> $firstname, $intYear, $year, .....
> How do you name your own functions ? drawLines(), setName, printHeading,
> heading, createaddress, ......
> How about exception or error handling?
> Since I am learning PHP I might as well learn it good.
>
> thanx,
>
> Pugi!


You essentially asked "how do you make chicken soup?". You'll get
everyone's different recipes. There are endless debates on what's the
proper parethesis style (same line vs. next line; indented to same level
or another level). Same with mixed case variables. Coming from
FORTRAN, I'm used to all the same case. I use all UPPERCASE for globals
and constants.

The question is are you the only one that's going to be using the code
or are you going to share it with others? If so, then find out what
their coding standards are and conform to them.

--
DeeDee, don't press that button! DeeDee! NO! Dee...



mhakes

2005-03-25, 3:56 pm

Pugi! wrote:
> Are there any standards about good coding practices in PHP ?
> Do you use capitals or not ? imagecreate or ImageCreate
> How do you name variables ? $arrColorBlack, $black, $strFirstName,
> $firstname, $intYear, $year, .....
> How do you name your own functions ? drawLines(), setName, printHeading,
> heading, createaddress, ......
> How about exception or error handling?
> Since I am learning PHP I might as well learn it good.
>
> thanx,
>
> Pugi!
>
>

I trust these guys: phpfreaks.com

http://www.phpfreaks.com/tutorials/35/0.php

mhakes
Jan Holland

2005-03-29, 3:56 pm

On Sat, 12 Feb 2005 15:55:08 +0100, "Pugi!" <reply@group> wrote:

>Are there any standards about good coding practices in PHP ?
>Do you use capitals or not ? imagecreate or ImageCreate
>How do you name variables ? $arrColorBlack, $black, $strFirstName,
>$firstname, $intYear, $year, .....
>How do you name your own functions ? drawLines(), setName, printHeading,
>heading, createaddress, ......
>How about exception or error handling?
>Since I am learning PHP I might as well learn it good.


I suggest that you first need to know
which tigers you want to fight.

If you know what to fight,
you can choose your weapons/methods.

Which editors are you going to use and
what are their possibilities ?

What are the methods of your colleagues or
are you living on an island?
--
Jan Holland
Posted by news://news.nb.nu
mhakes

2005-03-30, 3:56 pm

Pugi! wrote:
> Are there any standards about good coding practices in PHP ?
> Do you use capitals or not ? imagecreate or ImageCreate
> How do you name variables ? $arrColorBlack, $black, $strFirstName,
> $firstname, $intYear, $year, .....
> How do you name your own functions ? drawLines(), setName, printHeading,
> heading, createaddress, ......
> How about exception or error handling?
> Since I am learning PHP I might as well learn it good.
>
> thanx,
>
> Pugi!
>
>

I trust these guys: phpfreaks.com

http://www.phpfreaks.com/tutorials/35/0.php

mhakes
Kevin

2005-04-24, 8:55 am

Jan Holland wrote:
> On Sat, 12 Feb 2005 15:55:08 +0100, "Pugi!" <reply@group> wrote:
>
>
>
>
> I suggest that you first need to know
> which tigers you want to fight.
>
> If you know what to fight,
> you can choose your weapons/methods.
>
> Which editors are you going to use and
> what are their possibilities ?
>
> What are the methods of your colleagues or
> are you living on an island?
> --
> Jan Holland
> Posted by news://news.nb.nu


There are anumber of articles about good php coding at www.devshed.com

Good Luck

Kevin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com