Post your php programming tips here
Moderator: General Moderators
Post your php programming tips here
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.
do not make mistakes
Seriously, what kind of tips do you mean?
My first ones are:
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.is easier to read/debug thanTake 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
Seriously, what kind of tips do you mean?
My first ones are:
- note the Before Post Read in these topicnames
- Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+
- Sticky: Before Post Read: Warning: Cannot add header information
- Sticky: Before Post Read: Frames, JavaScript, and PHP Overview
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
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?';
?>Code: Select all
<?php // a example-script
echo 'e.g. easier to find the wrong string-format';
echo 'when it's colored';
echo 'see?';
?>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
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
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......
MyDimension is 100% right. Nothing helps more than this.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.
Other than that, thinking outside of the box is alright. Allways be open to new ideas.
Cheers,
BDKR
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
Code: Select all
echo("<font class="b">");Code: Select all
echo("<font class='b'>");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
why not simply?
Code: Select all
echo '<font class="b">';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.volka wrote:why not simply?Code: Select all
echo '<font class="b">';
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]
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
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.
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
}
//*/