Skip to content

Commit

Permalink
fixing errors and warnings for php 8.1
Browse files Browse the repository at this point in the history
- substr(): Passing null to parameter #1 ($string) of type string is deprecated
- strtolower(): Passing null to parameter #1 ($string) of type string is deprecated
- strlen(): Passing null to parameter #1 ($string) of type string is deprecated
- trim(): Passing null to parameter #1 ($string) of type string is deprecated
- str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated
- strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated
- http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated
- current(): Calling current() on an object is deprecated
- preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated
  • Loading branch information
falkenhawk committed Nov 29, 2022
1 parent 0de1e3b commit dbe52f7
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ public function setText($value)
*/
public function getText()
{
$text = $this->_text;
$text = (string) $this->_text;
if ($this->_withChecksum) {
$text .= $this->getChecksum($this->_text);
}
Expand Down Expand Up @@ -986,7 +986,7 @@ public function checkParams()
protected function _checkText($value = null)
{
if ($value === null) {
$value = $this->_text;
$value = (string) $this->_text;
}
if (!strlen($value)) {
// require_once 'Zend/Barcode/Object/Exception.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function setBody($body)
*/
public function getBody()
{
return $this->_body;
return is_string($this->_body) ? $this->_body : '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected function _formatName($unformatted, $isAction = false)
{
// preserve directories
if (!$isAction) {
$segments = explode($this->getPathDelimiter(), $unformatted);
$segments = explode($this->getPathDelimiter(), (string) $unformatted);
} else {
$segments = (array) $unformatted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function setBaseUrl($baseUrl = null)
}

// Does the baseUrl have anything in common with the request_uri?
$requestUri = $this->getRequestUri();
$requestUri = (string) $this->getRequestUri();

if (0 === strpos($requestUri, $baseUrl)) {
// full $baseUrl matches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function assemble($userParams, $name = null, $reset = false, $encode = tr
$url = $route->assemble($params, $reset, $encode);

if (!preg_match('|^[a-z]+://|', $url)) {
$url = rtrim($this->getFrontController()->getBaseUrl(), self::URI_DELIMITER) . self::URI_DELIMITER . $url;
$url = rtrim((string) $this->getFrontController()->getBaseUrl(), self::URI_DELIMITER) . self::URI_DELIMITER . $url;
}

return $url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ public function match($path, $partial = false)
// Translate value if required
$part = $this->_parts[$pos];
if ($this->_isTranslated
&& (substr($part, 0, 1) === '@' && substr($part, 1, 1) !== '@'
&& ($part !== null && substr($part, 0, 1) === '@' && substr($part, 1, 1) !== '@'
&& $name === null)
|| $name !== null && in_array($name, $this->_translatable)
) {
if (substr($part, 0, 1) === '@') {
if ($part !== null && substr($part, 0, 1) === '@') {
$part = substr($part, 1);
}

Expand All @@ -285,7 +285,7 @@ public function match($path, $partial = false)
}
}

if (substr($part, 0, 2) === '@@') {
if ($part !== null && substr($part, 0, 2) === '@@') {
$part = substr($part, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/zend-date/library/Zend/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ private function _date($calc, $date, $format, $locale)
}

$parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'locale' => $locale, 'format_type' => 'iso'));
if ((strpos(strtoupper($format), 'YY') !== false) and (strpos(strtoupper($format), 'YYYY') === false)) {
if (is_string($format) && (strpos(strtoupper($format), 'YY') !== false) and (strpos(strtoupper($format), 'YYYY') === false)) {
$parsed['year'] = self::getFullYear($parsed['year']);
}
} catch (Zend_Locale_Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-form/library/Zend/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ public function getId()
$id = $this->getFullyQualifiedName();

// Bail early if no array notation detected
if (!strstr($id, '[')) {
if ($id === null || !strstr($id, '[')) {
return $id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function render($content)
}

$description = $element->getDescription();
$description = trim($description);
$description = is_string($description) ? trim($description) : '';

if (!empty($description) && (null !== ($translator = $element->getTranslator()))) {
$description = $translator->translate($description);
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-form/library/Zend/Form/Decorator/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function getLabel()
}

$label = $element->getLabel();
$label = trim($label);
$label = is_string($label) ? trim($label) : '';

if (empty($label)) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-http/library/Zend/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ public function request($method = null)
if (! empty($query)) {
$query .= '&';
}
$query .= http_build_query($this->paramsGet, null, '&');
$query .= http_build_query($this->paramsGet, '', '&');
if ($this->config['rfc3986_strict']) {
$query = str_replace('+', '%20', $query);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/zend-http/library/Zend/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function getBody()
$body = '';

// Decode the body if it was transfer-encoded
switch (strtolower($this->getHeader('transfer-encoding'))) {
switch (strtolower((string) $this->getHeader('transfer-encoding'))) {

// Handle chunked body
case 'chunked':
Expand All @@ -275,7 +275,7 @@ public function getBody()
}

// Decode any content-encoding (gzip or deflate) if needed
switch (strtolower($this->getHeader('content-encoding'))) {
switch (strtolower((string) $this->getHeader('content-encoding'))) {

// Handle gzip encoding
case 'gzip':
Expand Down
8 changes: 4 additions & 4 deletions packages/zend-locale/library/Zend/Locale/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,14 @@ public static function getList($locale, $path, $value = false)
$val = implode('_' , $value);
}

$val = urlencode($val);
$val = urlencode((string) $val);
$id = self::_filterCacheId('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val);
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
return unserialize($result);
}

$temp = array();
switch(strtolower($path)) {
switch(strtolower((string) $path)) {
case 'language':
$temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language', 'type');
break;
Expand Down Expand Up @@ -982,13 +982,13 @@ public static function getContent($locale, $path, $value = false)
if (is_array($value)) {
$val = implode('_' , $value);
}
$val = urlencode($val);
$val = urlencode((string) $val);
$id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val);
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
return unserialize($result);
}

switch(strtolower($path)) {
switch(strtolower((string) $path)) {
case 'language':
$temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language[@type=\'' . $value . '\']', 'type');
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-translate/library/Zend/Translate/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ public function plural($singular, $plural, $number, $locale = null)
*/
protected function _log($message, $locale) {
if ($this->_options['logUntranslated']) {
$message = str_replace('%message%', $message, $this->_options['logMessage']);
$message = str_replace('%message%', (string) $message, $this->_options['logMessage']);
$message = str_replace('%locale%', $locale, $message);
if ($this->_options['log']) {
$this->_options['log']->log($message, $this->_options['logPriority']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/CodeGenerator/Php/ClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testPropertyAccessors()

$properties = $codeGenClass->getProperties();
$this->assertEquals(count($properties), 2);
$this->isInstanceOf(current($properties), 'Zend_CodeGenerator_Php_Property');
$this->isInstanceOf($properties->getIterator()->current(), 'Zend_CodeGenerator_Php_Property');

$property = $codeGenClass->getProperty('propTwo');
$this->isInstanceOf($property, 'Zend_CodeGenerator_Php_Property');
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testMethodAccessors()

$methods = $codeGenClass->getMethods();
$this->assertEquals(count($methods), 2);
$this->isInstanceOf(current($methods), 'Zend_CodeGenerator_Php_Method');
$this->isInstanceOf($methods->getIterator()->current(), 'Zend_CodeGenerator_Php_Method');

$method = $codeGenClass->getMethod('methodOne');
$this->isInstanceOf($method, 'Zend_CodeGenerator_Php_Method');
Expand Down

0 comments on commit dbe52f7

Please sign in to comment.