ID:               41450
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dead-krolik at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: any
 PHP Version:      6CVS-2007-05-20 (CVS)
 New Comment:

There is no real need for such a syntax.


Previous Comments:
------------------------------------------------------------------------

[2007-08-21 09:17:52] michael at chunkycow dot com dot au

What you want is fundamentally wrong and the wrong way to look at it,
having some sort of vahalla of acumulating data would be slow, bloated
and incredibly inflexible.
So to get the facts straight, you don`t want to define 1 extra variable
because your lazy and then request a language feature to support your
aversion to doing the right thing ?

Oh just thought of something, you can always use ob_start and friends
it's a global buffer of sorts or you can always just define your own.

------------------------------------------------------------------------

[2007-08-21 03:44:57] dead-krolik at gmail dot com

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.

------------------------------------------------------------------------

[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

Reply via email to