ForEach on array with dereferenced variable

Things you’d like to miss in the future...
Forum rules
:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:

:info: Please include the following information:
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".

:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:
Post Reply
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

ForEach on array with dereferenced variable

Post by PeterH »

ForEach($tok, *$var) (i.e. for a string) works OK
ForEach(*$var, ...) (i.e. for a dereferenced array) leads to ERROR 9 | Subscript out of range.

I'm convinced the second should work - especially as the first does?

Example, for string and for array:

Code: Select all

//§ Test ForEach with DeReference

"Test ForEach DeRef : TFEDR"
   STEP;
   $var  = '$p3';      // name of a parameter
   *$var = 'this|value';

   ForEach($tok, *$var, '|')   {   // this is OK
      echo "tok = $tok";
   }

   STEP;
   $var  = '$p4';      // another parameter
   Explode(*$var, $p3, '|');   // use previous string for new arrray

   ForEach(*$var as $ind => $val) { // ERROR 9 | Subscript out of range
      echo "$ind is $val";
   }
edit: replaced some tabs by " "
Last edited by PeterH on 03 Aug 2023 16:04, edited 1 time in total.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: ForEach on array with dereferenced variable

Post by PeterH »

Trying to circumvent the problem I tried to copy the (real) array before ForEach():

Code: Select all

   $p4 = an array like before
   $var = '$p4';
   $value = *$var; // ERROR: this assigns "" to $value
As before I tested a string instead of an array: no problem!

So dereference to a variable that's an array seems to generally fail.

admin
Site Admin
Posts: 66546
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: ForEach on array with dereferenced variable

Post by admin »

Always on the hunt, right? :) :tup:

Both confirmed and fixed! :cup:

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: ForEach on array with dereferenced variable

Post by PeterH »

admin wrote: 04 Aug 2023 11:52 Always on the hunt, right? :) :tup:
Sorry, but no :naughty:
I really use it :biggrin:

So in this case I had no choice: had to wait for your fix to continue. No circumvention.
But no rain in the moment: first will go to the forest!

Thanks for the fix: will test later!

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: ForEach on array with dereferenced variable

Post by PeterH »

Now it's later. (Much!)

After fixing my own :bug: :bug: :bug: ( :oops: )
I could verify: this :bug: is fixed, too!

So thanks again!

Post Reply