Skip to content

Commit 83f34f5

Browse files
authored
Merge pull request #3 from magento-trigger/php8.1-compatibility-fixes
Fixes for PHP 8.1 compatibility
2 parents c8ab365 + 438053d commit 83f34f5

File tree

11 files changed

+113
-39
lines changed

11 files changed

+113
-39
lines changed

library/Zend/Db/Adapter/Abstract.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,12 @@ public function quote($value, $type = null)
875875
return implode(', ', $value);
876876
}
877877

878+
$value = $value ?? '';
878879
if ($type !== null && array_key_exists($type = strtoupper($type), $this->_numericDataTypes)) {
879880
$quotedValue = '0';
880881
switch ($this->_numericDataTypes[$type]) {
881882
case Zend_Db::INT_TYPE: // 32-bit integer
882-
$quotedValue = (string) intval($value);
883+
$quotedValue = (string) ((int) $value);
883884
break;
884885
case Zend_Db::BIGINT_TYPE: // 64-bit integer
885886
// ANSI SQL-style hex literals (e.g. x'[\dA-F]+')

library/Zend/Db/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ protected function _join($type, $name, $cond, $cols, $schema = null)
819819
}
820820

821821
// Schema from table name overrides schema argument
822-
if (!is_object($tableName) && false !== strpos($tableName, '.')) {
822+
if ($tableName && !is_object($tableName) && (strpos($tableName, '.') !== false)) {
823823
list($schema, $tableName) = explode('.', $tableName);
824824
}
825825

library/Zend/Db/Statement.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,35 @@ abstract class Zend_Db_Statement implements Zend_Db_Statement_Interface
6464
*
6565
* @var array
6666
*/
67-
protected $_attribute = array();
67+
protected $_attribute = [];
6868

6969
/**
7070
* Column result bindings.
7171
*
7272
* @var array
7373
*/
74-
protected $_bindColumn = array();
74+
protected $_bindColumn = [];
7575

7676
/**
7777
* Query parameter bindings; covers bindParam() and bindValue().
7878
*
7979
* @var array
8080
*/
81-
protected $_bindParam = array();
81+
protected $_bindParam = [];
8282

8383
/**
8484
* SQL string split into an array at placeholders.
8585
*
8686
* @var array
8787
*/
88-
protected $_sqlSplit = array();
88+
protected $_sqlSplit = [];
8989

9090
/**
9191
* Parameter placeholders in the SQL string by position in the split array.
9292
*
9393
* @var array
9494
*/
95-
protected $_sqlParam = array();
95+
protected $_sqlParam = [];
9696

9797
/**
9898
* @var Zend_Db_Profiler_Query
@@ -134,14 +134,19 @@ protected function _prepare($sql)
134134
*/
135135
protected function _parseParameters($sql)
136136
{
137-
$sql = $this->_stripQuoted($sql);
138-
139-
// split into text and params
140-
$this->_sqlSplit = preg_split('/(\?|\:[a-zA-Z0-9_]+)/',
141-
$sql, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
137+
$this->_sqlSplit = [];
138+
if ($sql !== null) {
139+
$sql = $this->_stripQuoted($sql);
140+
$this->_sqlSplit = preg_split(
141+
'/(\?|\:[a-zA-Z0-9_]+)/',
142+
$sql,
143+
-1,
144+
PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY
145+
);
146+
}
142147

143148
// map params
144-
$this->_sqlParam = array();
149+
$this->_sqlParam = [];
145150
foreach ($this->_sqlSplit as $key => $val) {
146151
if ($val == '?') {
147152
if ($this->_adapter->supportsParameters('positional') === false) {
@@ -164,7 +169,7 @@ protected function _parseParameters($sql)
164169
}
165170

166171
// set up for binding
167-
$this->_bindParam = array();
172+
$this->_bindParam = [];
168173
}
169174

170175
/**
@@ -176,7 +181,6 @@ protected function _parseParameters($sql)
176181
*/
177182
protected function _stripQuoted($sql)
178183
{
179-
180184
// get the character for value quoting
181185
// this should be '
182186
$q = $this->_adapter->quote('a');

library/Zend/Db/Statement/Pdo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public function fetch($style = null, $cursor = null, $offset = null)
251251
$style = $this->_fetchMode;
252252
}
253253
try {
254-
return $this->_stmt->fetch($style, $cursor, $offset);
254+
return $this->_stmt->fetch($style, $cursor ?? PDO::FETCH_ORI_NEXT, $offset ?? 0);
255255
} catch (PDOException $e) {
256256
#require_once 'Zend/Db/Statement/Exception.php';
257257
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
@@ -263,6 +263,7 @@ public function fetch($style = null, $cursor = null, $offset = null)
263263
*
264264
* @return IteratorIterator
265265
*/
266+
#[\ReturnTypeWillChange]
266267
public function getIterator()
267268
{
268269
return new IteratorIterator($this->_stmt);

library/Zend/Http/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ public function request($method = null)
10411041
if (! empty($query)) {
10421042
$query .= '&';
10431043
}
1044-
$query .= http_build_query($this->paramsGet, null, '&');
1044+
$query .= http_build_query($this->paramsGet, '', '&');
10451045
if ($this->config['rfc3986_strict']) {
10461046
$query = str_replace('+', '%20', $query);
10471047
}

library/Zend/Http/Response.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,10 @@ public function isRedirect()
258258
public function getBody()
259259
{
260260
$body = '';
261+
$transferEncoding = $this->getHeader('transfer-encoding');
261262

262263
// Decode the body if it was transfer-encoded
263-
switch (strtolower($this->getHeader('transfer-encoding'))) {
264+
switch (($transferEncoding !== null) ? strtolower($transferEncoding) : '') {
264265

265266
// Handle chunked body
266267
case 'chunked':
@@ -274,8 +275,10 @@ public function getBody()
274275
break;
275276
}
276277

278+
$contentEncoding = $this->getHeader('content-encoding');
279+
277280
// Decode any content-encoding (gzip or deflate) if needed
278-
switch (strtolower($this->getHeader('content-encoding'))) {
281+
switch (($contentEncoding !== null) ? strtolower($contentEncoding) : '') {
279282

280283
// Handle gzip encoding
281284
case 'gzip':
@@ -603,7 +606,7 @@ public static function decodeChunkedBody($body)
603606
// If mbstring overloads substr and strlen functions, we have to
604607
// override it's internal encoding
605608
if (function_exists('mb_internal_encoding') &&
606-
((int) ini_get('mbstring.func_overload')) & 2) {
609+
((int) ini_get('mbstring.func_overload')) & 2) {
607610

608611
$mbIntEnc = mb_internal_encoding();
609612
mb_internal_encoding('ASCII');

library/Zend/Locale/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ public static function getContent($locale, $path, $value = false)
982982
if (is_array($value)) {
983983
$val = implode('_' , $value);
984984
}
985-
$val = urlencode($val);
985+
$val = ($val !== null) ? urlencode($val) : '';
986986
$id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val);
987987
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
988988
return unserialize($result);

library/Zend/Oauth/Http/Utility.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ public function generateTimestamp()
210210
*/
211211
public static function urlEncode($value)
212212
{
213-
$encoded = rawurlencode($value);
214-
$encoded = str_replace('%7E', '~', $encoded);
215-
return $encoded;
213+
return ($value !== null) ?
214+
str_replace('%7E', '~', rawurlencode($value)) : '';
216215
}
217216
}

library/Zend/Pdf/RecursivelyIteratableObjectsContainer.php

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,85 @@
2929
*/
3030
class Zend_Pdf_RecursivelyIteratableObjectsContainer implements RecursiveIterator, Countable
3131
{
32-
protected $_objects = array();
32+
protected $_objects = [];
3333

34-
public function __construct(array $objects) { $this->_objects = $objects; }
34+
/**
35+
* @param array $objects
36+
*/
37+
public function __construct(array $objects)
38+
{
39+
$this->_objects = $objects;
40+
}
3541

36-
public function current() { return current($this->_objects); }
37-
public function key() { return key($this->_objects); }
38-
public function next() { return next($this->_objects); }
39-
public function rewind() { return reset($this->_objects); }
40-
public function valid() { return current($this->_objects) !== false; }
41-
public function getChildren() { return current($this->_objects); }
42-
public function hasChildren() { return count($this->_objects) > 0; }
42+
/**
43+
* @inheritDoc
44+
*/
45+
#[\ReturnTypeWillChange]
46+
public function current()
47+
{
48+
return current($this->_objects);
49+
}
4350

44-
public function count() { return count($this->_objects); }
51+
/**
52+
* @inheritDoc
53+
*/
54+
#[\ReturnTypeWillChange]
55+
public function key()
56+
{
57+
return key($this->_objects);
58+
}
59+
60+
/**
61+
* @inheritDoc
62+
*/
63+
#[\ReturnTypeWillChange]
64+
public function next()
65+
{
66+
return next($this->_objects);
67+
}
68+
69+
/**
70+
* @inheritDoc
71+
*/
72+
#[\ReturnTypeWillChange]
73+
public function rewind()
74+
{
75+
return reset($this->_objects);
76+
}
77+
78+
/**
79+
* @inheritDoc
80+
*/
81+
#[\ReturnTypeWillChange]
82+
public function valid()
83+
{
84+
return current($this->_objects) !== false;
85+
}
86+
87+
/**
88+
* @inheritDoc
89+
*/
90+
#[\ReturnTypeWillChange]
91+
public function getChildren()
92+
{
93+
return current($this->_objects);
94+
}
95+
96+
/**
97+
* @inheritDoc
98+
*/
99+
#[\ReturnTypeWillChange]
100+
public function hasChildren()
101+
{
102+
return count($this->_objects) > 0;
103+
}
104+
105+
/**
106+
* @inheritDoc
107+
*/
108+
#[\ReturnTypeWillChange]
109+
public function count()
110+
{
111+
return count($this->_objects);
112+
}
45113
}

library/Zend/Registry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS)
201201
*
202202
* Workaround for http://bugs.php.net/bug.php?id=40442 (ZF-960).
203203
*/
204+
#[\ReturnTypeWillChange]
204205
public function offsetExists($index)
205206
{
206207
return array_key_exists($index, $this);
207208
}
208-
209209
}

library/Zend/Validate/File/Extension.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ public function setCase($case)
121121
*/
122122
public function getExtension()
123123
{
124-
$extension = explode(',', $this->_extension);
125-
126-
return $extension;
124+
return explode(',', $this->_extension);
127125
}
128126

129127
/**
@@ -134,7 +132,7 @@ public function getExtension()
134132
*/
135133
public function setExtension($extension)
136134
{
137-
$this->_extension = null;
135+
$this->_extension = '';
138136
$this->addExtension($extension);
139137
return $this;
140138
}

0 commit comments

Comments
 (0)