Broken arrays

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Raf
Posts: 128
Joined: 31 Jul 2024 15:34

Broken arrays

Post by Raf »

I'll start with a short message.
  • Arrays (by array I will mean 1D, 2D, ..., arrays and associative arrays) cannot be returned from functions.
  • It is not specified anywhere that an array can be passed to a function only if its argument is a reference to the array: function func(&$array){}. It is not mentioned anywhere that an operator & is needed.
  • The Help File doesn't say anything about creating a fixed-length array e.g. array[12]. But arrays can be filled in as simple C++ arrays: array[12]=value.
  • The index and values are interpolated/interpreted automatically, i.e. according to the Help, it is not necessary to use quotation marks in some cases: $array[key] = "value", $arr = array(val1, val2, ...). Thats why associative array in the for loop is filled incorrectly: for ($I=0, $I<$Len, $I++) {$dict[$I] = $i }. Guess what happens? Instead of the index $I (0, 1, ..., $Len), the string key $I is created ("0", "1", ..., " len"). That's it, an associative array cannot be filled in a loop by index.
I like writing scripts, but when I saw it all yesterday, I was horrified... Don, are you aware of these issues?

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

Re: Broken arrays

Post by admin »

XYS != C++

It's not broken, it's different.

Raf
Posts: 128
Joined: 31 Jul 2024 15:34

Re: Broken arrays

Post by Raf »

admin wrote: 13 Jan 2025 12:14 XYS != C++

It's not broken, it's different.
I feel C++ arrays vibe... Fortunately, the XY syntax is cleaner. Anyways, is there a chance to fix this issues?..

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

Re: Broken arrays

Post by admin »

By "fix" you mean nice-to-have enhancements. It's not impossible that they'll come one day.

Raf
Posts: 128
Joined: 31 Jul 2024 15:34

Re: Broken arrays

Post by Raf »

admin wrote: 13 Jan 2025 14:01 By "fix" you mean nice-to-have enhancements. It's not impossible that they'll come one day.
This is not an enhancement, associative arrays are useless:
Instead of the index $I (0, 1, ..., $Len), the string key $I is created ("0", "1", ..., " len"). That's it, an associative array cannot be filled in a loop by index.
and the lack of information in the Help makes arrays functionality hidden and incomprehensible.

I understand that it will take time, so I will wait for their improvement. My goal was to remind you of these issues.

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

Re: Broken arrays

Post by admin »

Your example has syntax errors. Nothing is broken with arrays if you write correct code:

Code: Select all

$a['pussy']="cat";
  $Len = 2;
  for ($i=0; $i<$Len; $i++) {
    $a[$i] = $i*10;
  }
  echo $a[$Len]; //10
  echo $a[1]; //10
  echo $a["1"]; //10
  echo $a["pussy"]; //cat

Post Reply