PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
First off what do you refer to these things as so in my future posts i dont have to refer to them as 'variable things'? $_POST['variable'], $_GET['variable'], $row['variable'] ect...
secondly, i downladed a code ive been modifying...below is an excerpt of the code
If you notice all the variable things are listed with outsingle quotes $row[t_views]. Is there any difference? Every time i use those variable things i always use the '' $row['t_views'], should i change them?
SidewinderX wrote:First off what do you refer to these things as so in my future posts i dont have to refer to them as 'variable things'? $_POST['variable'], $_GET['variable'], $row['variable'] ect...
The manual will tel you that quotes are optional. The thing to remember is that if you don't use quotes, PHP will assume that the index you chose should have been quoted or that the value you entered as an index is a constant. Clean coding tells you to wrap your array indeces in quotes.
I would also recommend using single quotes instead of double quotes. I am still looking for the benchmarks, but I read on the PHP web site that double quotes are unusually slow when it comes to parsing. Benchmarks showed that double quotes take almost four times as long to parse as opposed to double quotes.
plus, then you don't have to escape the double quotes in your html with a backslash. Also, I have heard it's faster to concatenate rather than pop variables directly into your strings so:
In my view this makes it more difficult to read the code though. It is just an alternative way.
Also, I remember reading somewhere (may even have been here) that the difference between single and double quotes is negligable when it comes to performance. I've got no hard evidence to back this up, so it could be wrong.
GM wrote:Also, I remember reading somewhere (may even have been here) that the difference between single and double quotes is negligable when it comes to performance. I've got no hard evidence to back this up, so it could be wrong.
julian_lp wrote:Please don't ever do that. It's really annoying.
Last time I checked "because some programmer finds it really annoying" was not a reason for choosing a programming practice -- if it was no one would be able to do anything.
julian_lp wrote:Always use ' instead of ", and concatenate the output as needed
Both are valid syntax in PHP and can be used as approprite and according to programmer preference.
and my 'myfunc' is basicly an alias to sprintf BUT, it checks md5(the 1st argument) in a mysql database and if the value in the DB is not the same as the 1st arg, it uses the DB value.
quite good if you want easy translate software, but slow... very slow.
julian_lp wrote:Please don't ever do that. It's really annoying.
Last time I checked "because some programmer finds it really annoying" was not a reason for choosing a programming practice -- if it was no one would be able to do anything.
You're absolutely right. But there seems to be some kind of agreed related to this topic. I mean, take 100 programmers and ask them about wich option they preffer, and you'll see that using
"/"{
is annoying.
having said that, everybody is free to choose any option
arborint wrote:
julian_lp wrote:Always use ' instead of ", and concatenate the output as needed
Both are valid syntax in PHP and can be used as approprite and according to programmer preference.
I've read somewhere that is considerably faster the ' than the ", beacause the parser doesn't try to find anything between ' .