Skip to content

Commit 10cd73a

Browse files
committed
eliminate PHP_VERSION_ID checks for < 80000 etc
1 parent 1455451 commit 10cd73a

15 files changed

+195
-571
lines changed

tests/array_access.phpt

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,25 @@ v8js.use_array_access = 1
77
--FILE--
88
<?php
99

10-
if (PHP_VERSION_ID < 80000) {
11-
class MyArray implements ArrayAccess, Countable {
12-
public function offsetExists($offset) {
13-
return $offset >= 0 && $offset <= 20;
14-
}
15-
16-
public function offsetGet($offset) {
17-
return 19 - $offset;
18-
}
10+
class MyArray implements ArrayAccess, Countable {
11+
public function offsetExists($offset): bool {
12+
return $offset >= 0 && $offset <= 20;
13+
}
1914

20-
public function offsetSet($offset, $value) {
21-
throw new Exception('Not implemented');
22-
}
15+
public function offsetGet(mixed $offset): mixed {
16+
return 19 - $offset;
17+
}
2318

24-
public function offsetUnset($offset) {
25-
throw new Exception('Not implemented');
26-
}
19+
public function offsetSet(mixed $offset, mixed $value): void {
20+
throw new Exception('Not implemented');
21+
}
2722

28-
public function count() {
29-
return 20;
30-
}
23+
public function offsetUnset(mixed $offset): void {
24+
throw new Exception('Not implemented');
3125
}
32-
} else {
33-
class MyArray implements ArrayAccess, Countable {
34-
public function offsetExists($offset): bool {
35-
return $offset >= 0 && $offset <= 20;
36-
}
37-
38-
public function offsetGet(mixed $offset): mixed {
39-
return 19 - $offset;
40-
}
41-
42-
public function offsetSet(mixed $offset, mixed $value): void {
43-
throw new Exception('Not implemented');
44-
}
45-
46-
public function offsetUnset(mixed $offset): void {
47-
throw new Exception('Not implemented');
48-
}
49-
50-
public function count(): int {
51-
return 20;
52-
}
26+
27+
public function count(): int {
28+
return 20;
5329
}
5430
}
5531

tests/array_access_001.phpt

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,31 @@ v8js.use_array_access = 1
77
--FILE--
88
<?php
99

10-
if (PHP_VERSION_ID < 80000) {
11-
class MyArray implements ArrayAccess, Countable {
12-
private $data = Array('one', 'two', 'three');
10+
class MyArray implements ArrayAccess, Countable {
11+
private $data = Array('one', 'two', 'three');
1312

14-
public function offsetExists($offset) {
15-
return isset($this->data[$offset]);
16-
}
17-
18-
public function offsetGet($offset) {
19-
return $this->data[$offset];
20-
}
21-
22-
public function offsetSet($offset, $value) {
23-
$this->data[$offset] = $value;
24-
}
25-
26-
public function offsetUnset($offset) {
27-
throw new Exception('Not implemented');
28-
}
29-
30-
public function count() {
31-
return count($this->data);
32-
}
33-
34-
public function push($value) {
35-
$this->data[] = $value;
36-
}
13+
public function offsetExists($offset): bool {
14+
return isset($this->data[$offset]);
3715
}
38-
} else {
39-
class MyArray implements ArrayAccess, Countable {
40-
private $data = Array('one', 'two', 'three');
4116

42-
public function offsetExists($offset): bool {
43-
return isset($this->data[$offset]);
44-
}
45-
46-
public function offsetGet(mixed $offset): mixed {
47-
return $this->data[$offset];
48-
}
17+
public function offsetGet(mixed $offset): mixed {
18+
return $this->data[$offset];
19+
}
4920

50-
public function offsetSet(mixed $offset, mixed $value): void {
51-
$this->data[$offset] = $value;
52-
}
21+
public function offsetSet(mixed $offset, mixed $value): void {
22+
$this->data[$offset] = $value;
23+
}
5324

54-
public function offsetUnset(mixed $offset): void {
55-
throw new Exception('Not implemented');
56-
}
25+
public function offsetUnset(mixed $offset): void {
26+
throw new Exception('Not implemented');
27+
}
5728

58-
public function count(): int {
59-
return count($this->data);
60-
}
29+
public function count(): int {
30+
return count($this->data);
31+
}
6132

62-
public function push($value) {
63-
$this->data[] = $value;
64-
}
33+
public function push($value) {
34+
$this->data[] = $value;
6535
}
6636
}
6737

tests/array_access_002.phpt

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,28 @@ Test V8::executeString() : Use ArrayAccess with JavaScript native push method
66
v8js.use_array_access = 1
77
--FILE--
88
<?php
9-
if (PHP_VERSION_ID < 80000) {
10-
class MyArray implements ArrayAccess, Countable {
11-
private $data = Array('one', 'two', 'three');
9+
class MyArray implements ArrayAccess, Countable {
10+
private $data = Array('one', 'two', 'three');
1211

13-
public function offsetExists($offset) {
14-
return isset($this->data[$offset]);
15-
}
16-
17-
public function offsetGet($offset) {
18-
return $this->data[$offset];
19-
}
12+
public function offsetExists($offset): bool {
13+
return isset($this->data[$offset]);
14+
}
2015

21-
public function offsetSet($offset, $value) {
22-
echo "set[$offset] = $value\n";
23-
$this->data[$offset] = $value;
24-
}
16+
public function offsetGet(mixed $offset): mixed {
17+
return $this->data[$offset];
18+
}
2519

26-
public function offsetUnset($offset) {
27-
throw new Exception('Not implemented');
28-
}
20+
public function offsetSet(mixed $offset, mixed $value): void {
21+
echo "set[$offset] = $value\n";
22+
$this->data[$offset] = $value;
23+
}
2924

30-
public function count() {
31-
return count($this->data);
32-
}
25+
public function offsetUnset(mixed $offset): void {
26+
throw new Exception('Not implemented');
3327
}
34-
} else {
35-
class MyArray implements ArrayAccess, Countable {
36-
private $data = Array('one', 'two', 'three');
37-
38-
public function offsetExists($offset): bool {
39-
return isset($this->data[$offset]);
40-
}
41-
42-
public function offsetGet(mixed $offset): mixed {
43-
return $this->data[$offset];
44-
}
45-
46-
public function offsetSet(mixed $offset, mixed $value): void {
47-
echo "set[$offset] = $value\n";
48-
$this->data[$offset] = $value;
49-
}
50-
51-
public function offsetUnset(mixed $offset): void {
52-
throw new Exception('Not implemented');
53-
}
54-
55-
public function count(): int {
56-
return count($this->data);
57-
}
28+
29+
public function count(): int {
30+
return count($this->data);
5831
}
5932
}
6033

tests/array_access_003.phpt

Lines changed: 32 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,39 @@ Test V8::executeString() : Export PHP methods on ArrayAccess objects
66
v8js.use_array_access = 1
77
--FILE--
88
<?php
9-
if (PHP_VERSION_ID < 80000) {
10-
class MyArray implements ArrayAccess, Countable {
11-
private $data = Array('one', 'two', 'three');
12-
13-
public function offsetExists($offset) {
14-
return isset($this->data[$offset]);
15-
}
16-
17-
public function offsetGet($offset) {
18-
return $this->data[$offset];
19-
}
20-
21-
public function offsetSet($offset, $value) {
22-
echo "set[$offset] = $value\n";
23-
$this->data[$offset] = $value;
24-
}
25-
26-
public function offsetUnset($offset) {
27-
throw new Exception('Not implemented');
28-
}
29-
30-
public function count() {
31-
echo 'count() = ', count($this->data), "\n";
32-
return count($this->data);
33-
}
34-
35-
public function phpSidePush($value) {
36-
echo "push << $value\n";
37-
$this->data[] = $value;
38-
}
39-
40-
public function push($value) {
41-
echo "php-side-push << $value\n";
42-
$this->data[] = $value;
43-
}
9+
class MyArray implements ArrayAccess, Countable {
10+
private $data = Array('one', 'two', 'three');
11+
12+
public function offsetExists($offset): bool {
13+
return isset($this->data[$offset]);
14+
}
15+
16+
public function offsetGet(mixed $offset): mixed {
17+
return $this->data[$offset];
18+
}
19+
20+
public function offsetSet(mixed $offset, mixed $value): void {
21+
echo "set[$offset] = $value\n";
22+
$this->data[$offset] = $value;
23+
}
24+
25+
public function offsetUnset(mixed $offset): void {
26+
throw new Exception('Not implemented');
27+
}
28+
29+
public function count(): int {
30+
echo 'count() = ', count($this->data), "\n";
31+
return count($this->data);
4432
}
45-
} else {
46-
class MyArray implements ArrayAccess, Countable {
47-
private $data = Array('one', 'two', 'three');
48-
49-
public function offsetExists($offset): bool {
50-
return isset($this->data[$offset]);
51-
}
52-
53-
public function offsetGet(mixed $offset): mixed {
54-
return $this->data[$offset];
55-
}
56-
57-
public function offsetSet(mixed $offset, mixed $value): void {
58-
echo "set[$offset] = $value\n";
59-
$this->data[$offset] = $value;
60-
}
61-
62-
public function offsetUnset(mixed $offset): void {
63-
throw new Exception('Not implemented');
64-
}
65-
66-
public function count(): int {
67-
echo 'count() = ', count($this->data), "\n";
68-
return count($this->data);
69-
}
70-
71-
public function phpSidePush($value) {
72-
echo "push << $value\n";
73-
$this->data[] = $value;
74-
}
75-
76-
public function push($value) {
77-
echo "php-side-push << $value\n";
78-
$this->data[] = $value;
79-
}
33+
34+
public function phpSidePush($value) {
35+
echo "push << $value\n";
36+
$this->data[] = $value;
37+
}
38+
39+
public function push($value) {
40+
echo "php-side-push << $value\n";
41+
$this->data[] = $value;
8042
}
8143
}
8244

0 commit comments

Comments
 (0)