Skip to content

Commit b24be5b

Browse files
committed
Fix warnings/deprecation notices with PHP 7.3+
- Array and string offset access syntax with curly braces is deprecated - The each() function is deprecated.
1 parent 099d0c0 commit b24be5b

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

Text/LanguageDetect.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function __construct()
189189
*/
190190
protected function _get_data_loc($fname)
191191
{
192-
if ($fname{0} == '/' || $fname{0} == '.') {
192+
if ($fname[0] == '/' || $fname[0] == '.') {
193193
// if filename starts with a slash, assume it's an absolute pathname
194194
// and skip whatever is in $this->_data_dir
195195
return $fname;
@@ -1470,31 +1470,31 @@ protected function _utf8char2unicode($char)
14701470
case 1:
14711471
// normal ASCII-7 byte
14721472
// 0xxxxxxx --> 0xxxxxxx
1473-
return ord($char{0});
1473+
return ord($char[0]);
14741474

14751475
case 2:
14761476
// 2 byte unicode
14771477
// 110zzzzx 10xxxxxx --> 00000zzz zxxxxxxx
1478-
$z = (ord($char{0}) & 0x000001F) << 6;
1479-
$x = (ord($char{1}) & 0x0000003F);
1478+
$z = (ord($char[0]) & 0x000001F) << 6;
1479+
$x = (ord($char[1]) & 0x0000003F);
14801480
return ($z | $x);
14811481

14821482
case 3:
14831483
// 3 byte unicode
14841484
// 1110zzzz 10zxxxxx 10xxxxxx --> zzzzzxxx xxxxxxxx
1485-
$z = (ord($char{0}) & 0x0000000F) << 12;
1486-
$x1 = (ord($char{1}) & 0x0000003F) << 6;
1487-
$x2 = (ord($char{2}) & 0x0000003F);
1485+
$z = (ord($char[0]) & 0x0000000F) << 12;
1486+
$x1 = (ord($char[1]) & 0x0000003F) << 6;
1487+
$x2 = (ord($char[2]) & 0x0000003F);
14881488
return ($z | $x1 | $x2);
14891489

14901490
case 4:
14911491
// 4 byte unicode
14921492
// 11110zzz 10zzxxxx 10xxxxxx 10xxxxxx -->
14931493
// 000zzzzz xxxxxxxx xxxxxxxx
1494-
$z1 = (ord($char{0}) & 0x00000007) << 18;
1495-
$z2 = (ord($char{1}) & 0x0000003F) << 12;
1496-
$x1 = (ord($char{2}) & 0x0000003F) << 6;
1497-
$x2 = (ord($char{3}) & 0x0000003F);
1494+
$z1 = (ord($char[0]) & 0x00000007) << 18;
1495+
$z2 = (ord($char[1]) & 0x0000003F) << 12;
1496+
$x1 = (ord($char[2]) & 0x0000003F) << 6;
1497+
$x2 = (ord($char[3]) & 0x0000003F);
14981498
return ($z1 | $z2 | $x1 | $x2);
14991499
}
15001500
}
@@ -1514,7 +1514,7 @@ protected function _utf8char2unicode($char)
15141514
*/
15151515
protected static function _next_char($str, &$counter, $special_convert = false)
15161516
{
1517-
$char = $str{$counter++};
1517+
$char = $str[$counter++];
15181518
$ord = ord($char);
15191519

15201520
// for a description of the utf8 system see
@@ -1538,7 +1538,7 @@ protected static function _next_char($str, &$counter, $special_convert = false)
15381538

15391539
} elseif ($ord >> 5 == 6) { // two-byte char
15401540
// multi-byte chars
1541-
$nextchar = $str{$counter++}; // get next byte
1541+
$nextchar = $str[$counter++]; // get next byte
15421542

15431543
// lower-casing of non-ascii characters is still incomplete
15441544

@@ -1580,12 +1580,12 @@ protected static function _next_char($str, &$counter, $special_convert = false)
15801580
} elseif ($ord >> 4 == 14) { // three-byte char
15811581

15821582
// tag on next 2 bytes
1583-
return $char . $str{$counter++} . $str{$counter++};
1583+
return $char . $str[$counter++] . $str[$counter++];
15841584

15851585
} elseif ($ord >> 3 == 30) { // four-byte char
15861586

15871587
// tag on next 3 bytes
1588-
return $char . $str{$counter++} . $str{$counter++} . $str{$counter++};
1588+
return $char . $str[$counter++] . $str[$counter++] . $str[$counter++];
15891589

15901590
} else {
15911591
// error?

tests/Text_LanguageDetectTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,23 +1445,28 @@ function testDetect()
14451445
$this->assertInternalType('array', $scores);
14461446
$this->assertGreaterThan(5, count($scores));
14471447

1448-
list($key, $value) = each($scores);
1448+
reset($scores);
1449+
$key = key($scores);
14491450
$this->assertEquals('german', $key, 'text is german');
14501451
}
14511452

14521453
function testDetectNameMode2()
14531454
{
14541455
$this->x->setNameMode(2);
14551456
$scores = $this->x->detect('Das ist ein kleiner Text für euch alle');
1456-
list($key, $value) = each($scores);
1457+
1458+
reset($scores);
1459+
$key = key($scores);
14571460
$this->assertEquals('de', $key, 'text is german');
14581461
}
14591462

14601463
function testDetectNameMode2Limit()
14611464
{
14621465
$this->x->setNameMode(2);
14631466
$scores = $this->x->detect('Das ist ein kleiner Text für euch alle', 1);
1464-
list($key, $value) = each($scores);
1467+
1468+
reset($scores);
1469+
$key = key($scores);
14651470
$this->assertEquals('de', $key, 'text is german');
14661471
}
14671472

0 commit comments

Comments
 (0)