tibberous Posted October 5, 2009 Share Posted October 5, 2009 I have the best idea ever for a language addition, a new escape character, \s It would look at the first proceeding numeric string, and evaluate to 's' unless it equaled 1. So, lets say you wanted to write: You have $x item(s) in your cart Instead of having to write: echo "You have $x item".($x==1?'':'s')." in your cart"; You could write: echo "You have $x item\s in your cart"; What do you guys think? I'd like to see it in PHP6. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/ Share on other sites More sharing options...
seventheyejosh Posted October 5, 2009 Share Posted October 5, 2009 what about words that pluralize with 'es'. i have 4 batch\s -> I have 4 batchs? Batchs != batches. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-930935 Share on other sites More sharing options...
Daniel0 Posted October 5, 2009 Share Posted October 5, 2009 Seems like a lot of work and extra overhead for a minor convenience feature. Anyways, if you want it in PHP then why not propose it on internals? Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-930936 Share on other sites More sharing options...
salathe Posted October 5, 2009 Share Posted October 5, 2009 I assume this will be locale specific and properly pluralize non-English words too? Right? Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931008 Share on other sites More sharing options...
.josh Posted October 5, 2009 Share Posted October 5, 2009 Also \s is already taken, so you'd have to either pick something else or go through the added effort to re-purpose what it is currently being used for. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931022 Share on other sites More sharing options...
Daniel0 Posted October 5, 2009 Share Posted October 5, 2009 Also \s is already taken, so you'd have to either pick something else or go through the added effort to re-purpose what it is currently being used for. For what? It isn't in the manual. http://dk2.php.net/manual/en/language.types.string.php#language.types.string.syntax.double Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931109 Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 It's used in Regex, but to my knowledge not in normal strings. Perhaps thats what Crayon Violent was thinking of. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931112 Share on other sites More sharing options...
.josh Posted October 5, 2009 Share Posted October 5, 2009 yes I was referring to its use in regex. IMO making it be what OP is proposing would cause confusion. Or not. Seems as though regex is some arcane gray area to most people... well I know you're decent at it Dan, must have slipped your mind. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931113 Share on other sites More sharing options...
corbin Posted October 5, 2009 Share Posted October 5, 2009 I think it would be pretty pointless. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931118 Share on other sites More sharing options...
Daniel0 Posted October 5, 2009 Share Posted October 5, 2009 Well, I know it's used for regex, but I don't see how that has anything to do with regular strings. The dollar sign also has special meaning in PCRE even though it's also used for variables. The string is parsed before it's passed to functions, so there would be no ambiguity. For instance, these will be parsed differently, but will do the same thing anyways: preg_replace('#\n#', '', $str); // vs preg_replace("#\n#", '', $str); I don't think the suggested feature is a good idea though. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931120 Share on other sites More sharing options...
.josh Posted October 5, 2009 Share Posted October 5, 2009 well that's because \n happens to mean the same thing for both regex and as an escaped char in strings. \s stands for a space, tab or newline char in regex, which is not even remotely the same thing as what the OP suggests it be used for. and the $ does mean something in regex. That's why you have to do all kinds of escaping with it, depending on what you're intention is. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931131 Share on other sites More sharing options...
Daniel0 Posted October 6, 2009 Share Posted October 6, 2009 and the $ does mean something in regex. That's why you have to do all kinds of escaping with it, depending on what you're intention is. Yeah, that's what I'm saying. It wouldn't result in any ambiguity because the parsing rules already dictate what would happen if \s was a valid escape sequence for double quoted strings. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931321 Share on other sites More sharing options...
Mchl Posted October 6, 2009 Share Posted October 6, 2009 Will it pluralize word in any language? If no I find it pretty useless. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931325 Share on other sites More sharing options...
.josh Posted October 6, 2009 Share Posted October 6, 2009 and the $ does mean something in regex. That's why you have to do all kinds of escaping with it, depending on what you're intention is. Yeah, that's what I'm saying. It wouldn't result in any ambiguity because the parsing rules already dictate what would happen if \s was a valid escape sequence for double quoted strings. Okay in something like this: $string = "blah blah blah\s"; There wouldn't be ambiguity because there's no regex happening. But if you are doing this: preg_match("~blah blah blah\s~",$string); so...what is that supposed to mean? A space/tab/newline, or a plural 'blah'? Using \n like that is okay because it happens to mean the same thing in both contexts, but it would not mean the same thing with \s. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931461 Share on other sites More sharing options...
Daniel0 Posted October 6, 2009 Share Posted October 6, 2009 That would depend on how you implemented the suggested plural \s escape sequence. There is not following anything that can be interpreted as an integer, so you could do two things: 1) ignore it and return verbatim, or 2) remove the \s. Because PHP is eagerly evaluated, argument parameters are evaluated before they are passed on to the functions. Therefore, substitutions in a double quoted string would be done before preg_match() even gets to take a look at it. If you wanted the PCRE \s you would have to either 1) use a single quoted string, or 2) escape the escape sequence. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931637 Share on other sites More sharing options...
tibberous Posted October 6, 2009 Author Share Posted October 6, 2009 \( would be cool to use if it wasn't used in regex. Then you could do: "You have $x item\(s)" "There are nine fish\(es)" That would really screw up regex though. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931723 Share on other sites More sharing options...
.josh Posted October 6, 2009 Share Posted October 6, 2009 Well regardless of nomenclature, I think you're putting the cart before the horse. As pointed out by many people, making a single escape char auto-pluralize something is not exactly a simple task...maybe even bordering on impossible. There are many rules to follow for pluralizing something, and it may or may not be pluralized the same way, depending on context and grammar of the rest of the sentence (assuming it was even written correctly to begin with)...and then multiply that by however many languages out there. Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931729 Share on other sites More sharing options...
Mchl Posted October 6, 2009 Share Posted October 6, 2009 I for one want a built-in declension support in PHP6 Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931739 Share on other sites More sharing options...
.josh Posted October 6, 2009 Share Posted October 6, 2009 I for one want a built-in declension support in PHP6 LoL how about a built-in function that returns all possible part of speech for a word? Quote Link to comment https://forums.phpfreaks.com/topic/176586-awesome-idea-for-a-php-language-addition/#findComment-931740 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.