#41450 [Opn]: New operator feature request

From: Date: Tue, 21 Aug 2007 03:44:57 +0000
Subject: #41450 [Opn]: New operator feature request
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116391@lists.php.net to get a copy of this message
ID: 41450 User updated by: dead-krolik at gmail dot com -Reported By: deadkrolik at gmail dot com +Reported By: dead-krolik at gmail dot com Status: Open Bug Type: Feature/Change Request Operating System: any PHP Version: 6CVS-2007-05-20 (CVS) New Comment: I know about references. Reference parameter it's the same like internal variable. I suggest new operator. And if we will use it - we will not need to define and use any variables. Previous Comments: ------------------------------------------------------------------------ [2007-08-20 22:33:18] michael at chunkycow dot com dot au Howdy you can use a reference parameter to accumulate values like this. function read_array($in, &$accumulator) { $out = array(); foreach(file($in) as $str) { $str = trim($str); //some modifications $out[] = $str; //OR $all_str .= $str $accumulator[] = $str; // or $accumulator .= $str; } return $out; } Now after you call the function the last parameter will hold all of the new values, this is a nasty way though and I would suggest you read some more about references(http://au2.php.net/manual/en/language.references.php). You can ofcourse use a global variable to store this aswell if it was an OO based thing (don`t use global keyword if your not using OO dear god please!). +1 for marking this as bogus, bad programming practice should not a language make :) ------------------------------------------------------------------------ [2007-05-20 18:07:52] dead-krolik at gmail dot com Description: ------------ It's not a bug, it's a new language operator suggestion. When I use other languages and PHP it's often were a one task - return values from function. I suggest a new operator and a don't know any analogs in other languages (may be I now small count of languages). Reproduce code: --------------- Task - return values from function with accumulating of results. For example, when we read strings from file and want return array of this strings (may be modified) from function we must accumulate/collect all values in array or in string: function read_array($in) { $out = array(); foreach(file($in) as $str) { $str = trim($str); //some modifications $out[] = $str; //OR $all_str .= $str } return $out; //OR return $all_str } It's a very often task. And may be it's will be useful for programers have two new operators - for strings and for arrays, that accumulate values within all function body and at the end return ALL strings/elements automatically. For example: function read_array($in) { foreach(file($in) as $str) { $str = trim($str); //some actions return_array $str;//accumulate $str to internal temporary array, that will be returned at the end of function } } And "return_string" for strings temporary buffer. -- Sorry for my terible English. With best regards Dead Krolik. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41450&edit=1

« previous php.bugs (#116391) next »