Skip to content

Commit

Permalink
fixing errors and warnings for php 8.1
Browse files Browse the repository at this point in the history
- imagefilledpolygon(): Using the $num_points parameter is deprecated
- Implicit conversion from float to int loses precision
- PDOStatement::bindParam(): Passing null to parameter #4 ($maxLength) of type int is deprecated
- preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated
- ctype_print(): Argument of type int will be interpreted as string in the future
-  trim(): Passing null to parameter #1 ($string) of type string is deprecated
  • Loading branch information
falkenhawk committed Dec 4, 2022
1 parent b90f64a commit 4f08129
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
14 changes: 9 additions & 5 deletions packages/zend-barcode/library/Zend/Barcode/Renderer/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ protected function _initRenderer()
throw $e;
}

$barcodeWidth = $this->_barcode->getWidth(true);
$barcodeHeight = $this->_barcode->getHeight(true);
$barcodeWidth = (int) $this->_barcode->getWidth(true);
$barcodeHeight = (int) $this->_barcode->getHeight(true);

if ($this->_resource !== null) {
$foreColor = $this->_barcode->getForeColor();
Expand Down Expand Up @@ -377,7 +377,11 @@ protected function _drawPolygon($points, $color, $filled = true)
);

if ($filled) {
imagefilledpolygon($this->_resource, $newPoints, 4, $allocatedColor);
if (PHP_VERSION_ID >= 80100) {
imagefilledpolygon($this->_resource, $newPoints, $allocatedColor);
} else {
imagefilledpolygon($this->_resource, $newPoints, 4, $allocatedColor);
}
} else {
imagepolygon($this->_resource, $newPoints, 4, $allocatedColor);
}
Expand Down Expand Up @@ -463,8 +467,8 @@ protected function _drawText($text, $size, $position, $font, $color, $alignment
$this->_resource,
$size,
$orientation,
$position[0] - ($width * cos(pi() * $orientation / 180)),
$position[1] + ($width * sin(pi() * $orientation / 180)),
round($position[0] - ($width * cos(pi() * $orientation / 180))),
round($position[1] + ($width * sin(pi() * $orientation / 180))),
$allocatedColor,
$font,
$text
Expand Down
13 changes: 8 additions & 5 deletions packages/zend-captcha/library/Zend/Captcha/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ protected function _generateImage($id, $word)
$textbox = imageftbbox($fsize, 0, $font, $word);
$x = ($w - ($textbox[2] - $textbox[0])) / 2;
$y = ($h - ($textbox[7] - $textbox[1])) / 2;
imagefttext($img, $fsize, 0, $x, $y, $text_color, $font, $word);
imagefttext($img, $fsize, 0, (int) $x, (int) $y, $text_color, $font, $word);

// generate noise
for ($i=0; $i<$this->_dotNoiseLevel; $i++) {
Expand Down Expand Up @@ -542,10 +542,12 @@ protected function _generateImage($id, $word)
if ($sx < 0 || $sy < 0 || $sx >= $w - 1 || $sy >= $h - 1) {
continue;
} else {
$color = (imagecolorat($img, $sx, $sy) >> 16) & 0xFF;
$color_x = (imagecolorat($img, $sx + 1, $sy) >> 16) & 0xFF;
$color_y = (imagecolorat($img, $sx, $sy + 1) >> 16) & 0xFF;
$color_xy = (imagecolorat($img, $sx + 1, $sy + 1) >> 16) & 0xFF;
$intsx = floor($sx);
$intsy = floor($sy);
$color = (imagecolorat($img, $intsx, $intsy) >> 16) & 0xFF;
$color_x = (imagecolorat($img, $intsx + 1, $intsy) >> 16) & 0xFF;
$color_y = (imagecolorat($img, $intsx, $intsy + 1) >> 16) & 0xFF;
$color_xy = (imagecolorat($img, $intsx + 1, $intsy + 1) >> 16) & 0xFF;
}
if ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255) {
// ignore background
Expand All @@ -564,6 +566,7 @@ protected function _generateImage($id, $word)
+ $color_x * $frac_x * $frac_y1
+ $color_y * $frac_x1 * $frac_y
+ $color_xy * $frac_x * $frac_y;
$newcolor = round($newcolor);
}
imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newcolor, $newcolor, $newcolor));
}
Expand Down
6 changes: 3 additions & 3 deletions packages/zend-db/library/Zend/Db/Adapter/Pdo/Pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,22 @@ public function describeTable($tableName, $schemaName = null)
foreach ($result as $key => $row) {
$defaultValue = $row[$default_value];
if ($row[$type] == 'varchar' || $row[$type] == 'bpchar' ) {
if (preg_match('/character(?: varying)?(?:\((\d+)\))?/', $row[$complete_type], $matches)) {
if (preg_match('/character(?: varying)?(?:\((\d+)\))?/', (string) $row[$complete_type], $matches)) {
if (isset($matches[1])) {
$row[$length] = $matches[1];
} else {
$row[$length] = null; // unlimited
}
}
if (preg_match("/^'(.*?)'::(?:character varying|bpchar)$/", $defaultValue, $matches)) {
if (preg_match("/^'(.*?)'::(?:character varying|bpchar)$/", (string) $defaultValue, $matches)) {
$defaultValue = $matches[1];
}
}
list($primary, $primaryPosition, $identity) = array(false, null, false);
if ($row[$contype] == 'p') {
$primary = true;
$primaryPosition = array_search($row[$attnum], explode(',', $row[$conkey])) + 1;
$identity = (bool) (preg_match('/^nextval/', $row[$default_value]));
$identity = (bool) (preg_match('/^nextval/', (string) $row[$default_value]));
}
$desc[$this->foldCase($row[$colname])] = array(
'SCHEMA_NAME' => $this->foldCase($row[$nspname]),
Expand Down
5 changes: 5 additions & 0 deletions packages/zend-db/library/Zend/Db/Statement/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ protected function _bindParam($parameter, &$variable, $type = null, $length = nu
$type = PDO::PARAM_STR;
}
}
if ($length === null) {
// PDOStatement::bindParam(): Passing null to parameter #4 ($maxLength) of type int is deprecated
// since php 8.1.0
$length = 0;
}
return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options);
} catch (PDOException $e) {
// require_once 'Zend/Db/Statement/Exception.php';
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-db/library/Zend/Db/Statement/Pdo/Ibm.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function _bindParam($parameter, &$variable, $type = null, $length = null,
if (($type === null) && ($length === null) && ($options === null)) {
return $this->_stmt->bindParam($parameter, $variable);
} else {
return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options);
return $this->_stmt->bindParam($parameter, $variable, $type, $length === null ? 0 : $length, $options);
}
} catch (PDOException $e) {
// require_once 'Zend/Db/Statement/Exception.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function _setKeys($keys)
}

foreach ($keys as $type => $key) {
if (ctype_print($key) && is_file(realpath($key)) && is_readable($key)) {
if (ctype_print((string) $key) && is_file(realpath($key)) && is_readable($key)) {
$file = fopen($key, 'r');
$cert = fread($file, 8192);
fclose($file);
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-ldap/library/Zend/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function setOptions($options)
$val === '1' || strcasecmp($val, 'true') == 0);
break;
default:
$permittedOptions[$key] = trim($val);
$permittedOptions[$key] = trim((string) $val);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ public function setWidth($width = null)
$this->_width = 80;

// Try to determine the width through stty
if (preg_match('#\d+ (\d+)#', @shell_exec('stty size'), $match) === 1) {
if (preg_match('#\d+ (\d+)#', (string) @shell_exec('stty size'), $match) === 1) {
$this->_width = (int) $match[1];
} else if (preg_match('#columns = (\d+);#', @shell_exec('stty'), $match) === 1) {
} else if (preg_match('#columns = (\d+);#', (string) @shell_exec('stty'), $match) === 1) {
$this->_width = (int) $match[1];
}
}
Expand Down

0 comments on commit 4f08129

Please sign in to comment.