Skip to content

Commit 8f87c72

Browse files
committed
Handle null byte detection based on PHP version in Column class (support for PHP >= 8)
1 parent d861126 commit 8f87c72

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

src/XBase/Column.php

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?php
1+
<?php
22

33
namespace XBase;
44

5-
class Column
5+
class Column
66
{
77

88
public $name;
@@ -18,10 +18,11 @@ class Column
1818
protected $bytePos;
1919
protected $colIndex;
2020

21-
public function __construct($name, $type, $memAddress, $length, $decimalCount, $reserved1, $workAreaID, $reserved2, $setFields, $reserved3, $indexed, $colIndex, $bytePos)
21+
public function __construct($name, $type, $memAddress, $length, $decimalCount, $reserved1, $workAreaID, $reserved2, $setFields, $reserved3, $indexed, $colIndex, $bytePos)
2222
{
2323
$this->rawname = $name;
24-
$this->name = (strpos($name, 0x00) !== false ) ? substr($name, 0, strpos($name, 0x00)) : $name;
24+
$needle = PHP_VERSION_ID >= 80000 ? "\0" : 0x00;
25+
$this->name = (strpos($name, $needle) !== false ) ? substr($name, 0, strpos($name, $needle)) : $name;
2526
$this->type = $type;
2627
$this->memAddress = $memAddress;
2728
$this->length = $length;
@@ -33,23 +34,23 @@ public function __construct($name, $type, $memAddress, $length, $decimalCount, $
3334
$this->colIndex = $colIndex;
3435
}
3536

36-
37-
public function getDecimalCount()
37+
38+
public function getDecimalCount()
3839
{
3940
return $this->decimalCount;
4041
}
41-
42-
public function isIndexed()
42+
43+
public function isIndexed()
4344
{
4445
return $this->indexed;
4546
}
46-
47-
public function getLength()
47+
48+
public function getLength()
4849
{
4950
return $this->length;
5051
}
51-
52-
public function getDataLength()
52+
53+
public function getDataLength()
5354
{
5455
switch ($this->type) {
5556
case Record::DBFFIELD_TYPE_DATE : return 8;
@@ -59,48 +60,48 @@ public function getDataLength()
5960
default : return $this->length;
6061
}
6162
}
62-
63-
public function getMemAddress()
63+
64+
public function getMemAddress()
6465
{
6566
return $this->memAddress;
6667
}
67-
68-
public function getName()
68+
69+
public function getName()
6970
{
7071
return $this->name;
7172
}
72-
73-
public function isSetFields()
73+
74+
public function isSetFields()
7475
{
7576
return $this->setFields;
7677
}
77-
78-
public function getType()
78+
79+
public function getType()
7980
{
8081
return $this->type;
8182
}
82-
83-
public function getWorkAreaID()
83+
84+
public function getWorkAreaID()
8485
{
8586
return $this->workAreaID;
8687
}
87-
88-
public function toString()
88+
89+
public function toString()
8990
{
9091
return $this->name;
9192
}
92-
93-
public function getBytePos()
93+
94+
public function getBytePos()
9495
{
9596
return $this->bytePos;
9697
}
97-
98-
public function getRawname()
98+
99+
public function getRawname()
99100
{
100101
return $this->rawname;
101102
}
102-
103-
public function getColIndex()
103+
104+
public function getColIndex()
104105
{
105106
return $this->colIndex;
106107
}

0 commit comments

Comments
 (0)