php / php/doc-en

Randomizer::pickArrayKeys() has intransparent external behavior

Open
#1,731 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: random
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Description

The following code:

<?php

$r1 = new Random\Randomizer(new Random\Engine\Xoshiro256StarStar(1));
$r2 = new Random\Randomizer(new Random\Engine\Xoshiro256StarStar(1));

$a = [ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, ];
unset($a['b']);

$b = [ 'a' => 1, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, ];

var_dump($a === $b); // bool(true)

var_dump(
	$r1->pickArrayKeys($a, 1), // [ 0 => 'e' ]
	$r2->pickArrayKeys($b, 1), // [ 0 => 'd' ]
);

Resulted in this output:

bool(true)
array(1) {
  [0]=>
  string(1) "e"
}
array(1) {
  [0]=>
  string(1) "d"
}

But I expected this output instead:

The same key selected, because the arrays are identical.

PHP Version

Current git master

Operating System

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's reproducible example and the PHP documentation for Randomizer::pickArrayKeys(). Determine whether the differing selections for arrays with identical key-value pairs are expected, then clarify the documented behavior and expected result; no specific file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.