File: igbinary_enums_1.phpt

package info (click to toggle)
php-igbinary 3.2.16-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,024 kB
  • sloc: ansic: 3,373; xml: 1,106; pascal: 10; makefile: 2; php: 2; sh: 1
file content (41 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--TEST--
Test unserializing valid enums
--SKIPIF--
<?php if (PHP_VERSION_ID < 80100) { echo "skip enums requires php 8.1"; } ?>
--FILE--
<?php

enum Suit {
    case Hearts;
    case Diamonds;
    case Spades;
    case Clubs;
}
$ser = igbinary_serialize(Suit::Hearts);
echo urlencode($ser), "\n";
var_dump(igbinary_unserialize($ser));
var_dump(igbinary_unserialize($ser));
$serArray = igbinary_serialize([Suit::Hearts, Suit::Diamonds, Suit::Spades, Suit::Clubs, Suit::Clubs, 'Diamonds' => 'Diamonds']);
echo urlencode($serArray), "\n";
var_dump(igbinary_unserialize($serArray));

?>
--EXPECT--
%00%00%00%02%17%04Suit%27%11%06Hearts
enum(Suit::Hearts)
enum(Suit::Hearts)
%00%00%00%02%14%06%06%00%17%04Suit%27%11%06Hearts%06%01%1A%00%27%11%08Diamonds%06%02%1A%00%27%11%06Spades%06%03%1A%00%27%11%05Clubs%06%04%22%04%0E%02%0E%02
array(6) {
  [0]=>
  enum(Suit::Hearts)
  [1]=>
  enum(Suit::Diamonds)
  [2]=>
  enum(Suit::Spades)
  [3]=>
  enum(Suit::Clubs)
  [4]=>
  enum(Suit::Clubs)
  ["Diamonds"]=>
  string(8) "Diamonds"
}