Maybe they should have used + for concatenation and . for dereferencing...
I find myself constantly mucking up the characters ->
Bah...end of rant...
Petition anyone?
Moderator: General Moderators
Counter-intuitive? How so?AKA Panama Jack wrote:Nope, using the . would have been counter intuitive.
Perhaps, but PHP supports various CRT style functions, which should be used over concatenation operator anyways (sprintf and company) so they could do away with the '.' operator as concatenation and use it for member access instead.feyd wrote:Considering it would likely take more time to process your code into operations when making the same operator doing multiple things in context, I think the sacrifice of some extra typing is perfectly acceptable. Java and C have the luxury of a compilation, Javascript has the luxury of being a light load for a client, but a server parsing untold numbers of files at any given time, well, you get the idea, right?
sprintf et al are completely impractical for most string operations in this language. Why do you think C++ added the String class and Java natively has a String class which is always included?Hockey wrote:Perhaps, but PHP supports various CRT style functions, which should be used over concatenation operator anyways (sprintf and company) so they could do away with the '.' operator as concatenation and use it for member access instead.
How could we possibly know you are joking? Many-a-time have you posted of similar outlandish, neigh impossible, ideas and were totally serious. If you need your memory jogged, how about the time you wanted to create and thereby impose a coding style. I'd say that's pretty similar in the "it won't happen, ever" scenario that you're fairly well known for. Whether that's a bad or good thing, hard to say.Hockey wrote:Of course, you realize that is a joke? Apparently I have to make this clear because many of you seem to think I am serious or that unpractical.
I'm curious why they are impractical? I personally prefer sprintf over string concatenation operators. For starters I imagine it's faster than relying on:feyd wrote:sprintf et al are completely impractical for most string operations in this language. Why do you think C++ added the String class and Java natively has a String class which is always included?Hockey wrote:Perhaps, but PHP supports various CRT style functions, which should be used over concatenation operator anyways (sprintf and company) so they could do away with the '.' operator as concatenation and use it for member access instead.
How could we possibly know you are joking? Many-a-time have you posted of similar outlandish, neigh impossible, ideas and were totally serious. If you need your memory jogged, how about the time you wanted to create and thereby impose a coding style. I'd say that's pretty similar in the "it won't happen, ever" scenario that you're fairly well known for. Whether that's a bad or good thing, hard to say.Hockey wrote:Of course, you realize that is a joke? Apparently I have to make this clear because many of you seem to think I am serious or that unpractical.
Code: Select all
$str = 'this'.'is'.'a'.'string';Code: Select all
$str = sprintf('%s%s%s%s', 'this', 'is', 'a', 'string');Perhaps for simple concatenation.feyd wrote:I fully agree sprintf() has it's uses, but straight concatenation is just not one of them in PHP.
- It's interesting to see you tout the use of sprintf() when you are often one to go for less keystrokes and "easy."
- I wasn't referring to MFC and CString, I was talking about the STL's String.
- Java has sprintf in the String class, but to use it for concatenation is just normally not done; it's silly when the plus operator they've provided for it is right at hand.
Code: Select all
$firstname.$lastnameCode: Select all
$fullname = $firstname.' '.$lastname;Code: Select all
$fullname = sprintf('%s %s', $firstname, $lastname);Code: Select all
define('FULLNAME', '%s, %s'); // Format a name nicely - not adhoc hackish like concatenation.
$fullname = sprintf(FULLNAME, $firstname, $lastname);Code: Select all
define('SEPARATOR', ',');
$fullname = $firstname.SEPARATOR.$lastname;Code: Select all
echo $name.' - '.$age.'<br>';I think I would define it as: Used to dereference object member variables.superdezign wrote:In C++, the -> operator is used to access members of references
Yup, but PHP 4 doesn't, so what? You still use the '->' operator.superdezign wrote:PHP 5 automatically uses object references. Just though I should trow that out there