Page 1 of 1
Post your php programming tips here
Posted: Wed Oct 30, 2002 7:23 pm
by Kyori
post helpful tips on proper php programming. Also put whether it's about security, querries, etc. May these be the newbies read first thread. thanks. I'm a new myself.
Posted: Wed Oct 30, 2002 8:39 pm
by volka
do not make mistakes
Seriously, what kind of tips do you mean?
My first ones are:
http://www.php.net/manual/en/ and
www.google.com are your friends. Make intense use of them.
Maybe the problem is covered by a tutorial, maybe even at
http://www.phpcomplete.com/ (that's the link at top of the page)
If your problem is of general nature ("how do I ...") it is likely that someone already asked before

search
this forum or some more via
phuse
Keep your code readable! note
http://forums.devnetwork.net/viewtopic.php?t=3173. These styles differ not that much among one another - and that for some reason.....
Syntaxhighlighting editors can be of great help.
Code: Select all
<?php // a example-script
echo 'e.g. easier to find the wrong string-format';
echo 'when it's colored';
echo 'see?';
?>
is easier to read/debug than
Code: Select all
<?php // a example-script
echo 'e.g. easier to find the wrong string-format';
echo 'when it's colored';
echo 'see?';
?>
Take a look e.g. at
http://forums.devnetwork.net/viewtopic.php?t=3495
When your project gets more complex and more complex errors occure you will appreciate the help a debugger offers. printf/echo-debugging sometimes may be feasable but a real debugger is better
http://www.php.net/manual/en/debugger.php
DBG: Php Debugger
Posted: Wed Oct 30, 2002 11:17 pm
by mydimension
before you do any coding (esp. on a larger application) break out a notebook and a pencil and think through how your application is going to function, the resources it is going to need and what the output will look like. nothing beats outlining your project before hand, it helps to sort your thoughts before you bumble your code.
X......
Posted: Thu Oct 31, 2002 6:53 am
by BDKR
before you do any coding (esp. on a larger application) break out a notebook and a pencil and think through how your application is going to function, the resources it is going to need and what the output will look like. nothing beats outlining your project before hand, it helps to sort your thoughts before you bumble your code.
MyDimension is 100% right. Nothing helps more than this.
Other than that, thinking outside of the box is alright. Allways be open to new ideas.
Cheers,
BDKR
Posted: Thu Oct 31, 2002 12:08 pm
by seg
I see a lot of programmers using \" in variables and echo functions to output the ". Most times this is used in html code, like
I find this unnecesary, I just use the '
I've made it a habit while writting html code to always use the ' instead of ". It saves a character, and i think it looks better. So far I have not come across a browser that couldnt deal with a ' instead of a ".
And this is a good read. I'm a bad('coder'); too, so don't feel bad if you do these things.
http://www.evilwalrus.com/articles/read.php?aid=16
Posted: Thu Oct 31, 2002 12:51 pm
by volka
Posted: Thu Oct 31, 2002 1:05 pm
by seg
volka wrote:why not simply
?
Yeah, you are right. It's that whole "learn something new every day". Way i figure it, if you use echo "... then you can use the ' as a quote in the string, and if you use echo '... then you can use ". After reading the evilwalrus article i posted the link for, I won't be using () any more.
Posted: Thu Oct 31, 2002 2:58 pm
by volka
took me some time to get over that "beh, looks like shell-scripting" but now I'm (almost) always using echo string,string,string rather than print(string.string.string)
Posted: Thu Oct 31, 2002 3:22 pm
by infolock
Lots more that can't even be covered here, but other major things to remember are :
Ask yoursefl :
Will sensative information be secure if I send it this way?
Get some friends of yours that like to break into systems, and see if they can gain superuser rights through a vulnerability in your script
Use good error handling skills. If you think a portion of your script is buggy, or not working, try putting error handlings between the lines, and see which one generates the error. Easiest way to debugging.
Don't be afraid. PHP is very coder friendly, and very, VERY superior if you can master it.
Above all, view other people's scripts. Look at their problems they are having, how they resolved it, or how they wrote their code that does the same thing as yours, and find their strengths and weaknesses and variations.
Other then that, that's about the only thing I can give ya coming from a n00b

[/b]
Posted: Fri Nov 01, 2002 7:16 am
by davro
Don`t know if this is legal, but works for me use this quite a lot to comment out large areas of code.
comment, uncomment ect.
Code: Select all
///*
function test ()
{
// blah code
}
function comments ()
{
// moreblah code
}
//*/
// can eaily be commented out like so
/*
function test ()
{
// blah code
}
function comments ()
{
// moreblah code
}
//*/
Posted: Fri Nov 01, 2002 5:13 pm
by Porter
Remember to check the PHP Manual for functions for doing things that seem pretty simple to do. It'll save a ton of time.