Page 1 of 1

foreach-bug ?

Posted: 12 Sep 2016 16:02
by autocart
1) create a new EMPTY txt file.
2) run this code:

Code: Select all

$fileText = readfile(inputfile(<curpath>, "txt", "Choose an empty txt file."));
  foreach($line, $fileText, "<crlf>", , "empty")
  {
    echo $line;
  }
3) admire the bug ;-)

Re: foreach-bug ?

Posted: 12 Sep 2016 17:32
by admin
What bug?

Re: foreach-bug ?

Posted: 12 Sep 2016 17:37
by autocart
alright,...
according to the help file there should be a message.
instead i get a scripting error with the scripting error box.

Re: foreach-bug ?

Posted: 12 Sep 2016 17:39
by highend
It's a scripting error message, not a messagebox

Re: foreach-bug ?

Posted: 12 Sep 2016 17:40
by autocart
aha, well, the help file could be clearer on this ... but now I know. thx.

Re: foreach-bug ?

Posted: 12 Sep 2016 17:41
by admin
autocart wrote:according to the help file there should be a message.
Not just a message, an "error message". And that's what you get. :)

Re: foreach-bug ?

Posted: 12 Sep 2016 17:46
by autocart
well, at least I was right with the question mark in the title.

Re: foreach-bug ?

Posted: 12 Sep 2016 18:07
by admin
:biggrin:

Re: foreach-bug ?

Posted: 12 Sep 2016 18:31
by bdeshi
[let me try probably invent a bug from thin air]
foreach reference remarks wrote:The separator defaults to "|" (pipe), but can be set to anything, also multi-character strings.
Since <an empty thing> is a subset of <anything>, So the separator can be an empty string. Therefore, this script should be able to loop through the characters in a string by setting the separator to empty. Which is not what happens.

Code: Select all

::$string='string'; foreach($letter, $string, ''){ echo $letter; }

Re: foreach-bug ?

Posted: 13 Sep 2016 08:24
by admin
I take this as a wish rather than a bug, and I Iike it. Coming...

Re: foreach-bug ?

Posted: 13 Sep 2016 09:11
by Filehero
Sammay, a char-iterator is really a cool idea. :tup: