I’ve just been going through the System log on a computer at work and found it was having trouble locating the time-server. I used the net time command and must say I found the message so helpful.
Z:\>net time
Could not locate a time-server.
More help is available by typing NET HELPMSG 3912.
Z:\>net helpmsg 3912
Could not locate a time-server.
Sarcasm should be noted. (Also, the sky seems very red at the moment, despite the rain, so it may well be the end of the world).
Damn it PHP pisses me off some times. I can tolerate the ‘$’’s, as annoying as they are, but why oh why didn’t they make ‘+’ string concatenation like everyone else? What’s worse is that you don’t get a warning or anything, it just silently ignores it. Grrr!
Will.
Well, the reason why it doesn’t give you a warning is because of the whole looseness of PHP variables. Typically a string that isn’t a number corresponds to zero (I think), so it just does the maths based on that. It is particularly useful when you have the empty string (which if you are doing maths typically should be zero).
The fact is that “+” is a mathematical operator. Visual Basic uses an ampersand (&) to concatenate strings. The operations are quite different and using a different operator can assist in the readability of code.
It’s the lack of warnings that gets to me. It reminds me of coding VB without Option Explicit set to on (or QBASIC which doesn’t have this option). I can remember wasting hours debugging only to find that I’d typoed a variable name :-S
Will.
It comes back to context. If you have a “+”, PHP sees this as addition and looks at the numerical value of the variable (which in a string may actually be a number (e.g. if the string is “22″). PHP and in fact any programming language should not need to provide a warning when an operator is used in the wrong context.
This is a “by design” thing.
It’s not a bug, it’s a feature
Will.
Reminds me of something I saw on our work computers the other day. “Please see the log file for details”. So I go to the log file, and what do I find written in the log file?
“Please see the log file for details.”
It’s a good thing I stopped following the instructions after that or I could have died of old age before solving that problem.