File: dim_assign_001.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (24 lines) | stat: -rw-r--r-- 926 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--TEST--
JIT - Assigning to arrays using string key which parses to an integer
--FILE--
<?php
/* We are going to store a value in an array, using the key "1"
 * PHP should always convert such strings to integers when storing or retrieving
 * values from an array
 *
 * We'll do it in a loop, so that if JIT is enabled, the code will be JIT'd
 * (Because this test was originally added as a regression test for a JIT bug)
 *
 * Also, the test will do this in a way which guarantees PHP won't be able to
 * predict whether the (string) key will be a numeric string or not */
$fp = fopen(realpath(__DIR__ . '/dim_assign_001.txt'), 'r+');
$array = array();
while ($line = fgets($fp, 256)) {
  sscanf($line, '%x', $char);
  $char = chr($char);
  $array[$char] = "Values can be stored correctly using numeric string keys";
}
var_dump($array['1']);
?>
--EXPECT--
string(56) "Values can be stored correctly using numeric string keys"