Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch ValueError on PHP 8.0 for Pdo Statement #85

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,9 @@ jobs:
matrix:
experimental:
- false
php:
- "5.3"
- "5.4"
- "5.5"
- "5.6"
- "7.0"
- "7.1"
- "7.2"
- "7.3"
- "7.4"
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-including-additional-values-into-combinations
include:
- php: "8.0"
experimental: true
runs-on: ubuntu-20.04

env:
Expand Down Expand Up @@ -86,6 +75,6 @@ jobs:
- name: "Run PHPUnit tests (Experimental: ${{ matrix.experimental }})"
env:
FAILURE_ACTION: "${{ matrix.experimental == true }}"
run: vendor/bin/phpunit --verbose || $FAILURE_ACTION
run: vendor/bin/phpunit --verbose tests/Zend/Db || $FAILURE_ACTION

# vim:ft=yaml:et:ts=2:sw=2
13 changes: 12 additions & 1 deletion packages/zend-db/library/Zend/Db/Adapter/Db2.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
*
* @var int execution flag (DB2_AUTOCOMMIT_ON or DB2_AUTOCOMMIT_OFF)
*/
protected $_execute_mode = DB2_AUTOCOMMIT_ON;
protected $_execute_mode;

/**
* Default class name for a DB statement.
Expand Down Expand Up @@ -111,6 +111,17 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
'NUMERIC' => Zend_Db::FLOAT_TYPE
);

public function __construct($config)
{
// Only assign the value if constant is present
// The required extension check is performed in _connect()
if (defined('DB2_AUTOCOMMIT_ON')) {
$this->_execute_mode = DB2_AUTOCOMMIT_ON;
}

parent::__construct($config);
}

/**
* Creates a connection resource.
*
Expand Down
10 changes: 10 additions & 0 deletions packages/zend-db/library/Zend/Db/Statement/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ public function fetch($style = null, $cursor = null, $offset = null)
}
try {
return $this->_stmt->fetch($style, $cursor, $offset);
} catch (ValueError $e) {
// require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode());
} catch (PDOException $e) {
// require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
Expand Down Expand Up @@ -290,6 +293,9 @@ public function fetchAll($style = null, $col = null)
} else {
return $this->_stmt->fetchAll($style);
}
} catch (ValueError $e) {
// require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode());
} catch (PDOException $e) {
// require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
Expand Down Expand Up @@ -431,6 +437,10 @@ public function setFetchMode($mode)
$this->_fetchMode = $mode;
try {
return $this->_stmt->setFetchMode($mode);
} catch (ValueError $e) {
// require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode());

} catch (PDOException $e) {
// require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
Expand Down
3 changes: 3 additions & 0 deletions packages/zend-db/library/Zend/Db/Statement/Pdo/Ibm.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public function _bindParam($parameter, &$variable, $type = null, $length = null,
} else {
return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options);
}
} catch (ValueError $e) {
// require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode());
} catch (PDOException $e) {
// require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
Expand Down
21 changes: 19 additions & 2 deletions packages/zend-log/library/Zend/Log/Writer/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ public function __construct($streamOrUrl, $mode = null)
$streamOrUrl = $streamOrUrl['stream'];
}

if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
try {
$this->_stream = @fopen($streamOrUrl, $mode, false);
} catch (ValueError $e) {
// require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception($e->getMessage(), $e->getCode());
} catch (TypeError $e) {
// require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception($e->getMessage(), $e->getCode());
}

if (!$this->_stream) {
// require_once 'Zend/Log/Exception.php';
$msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
throw new Zend_Log_Exception($msg);
Expand Down Expand Up @@ -130,7 +140,14 @@ protected function _write($event)
{
$line = $this->_formatter->format($event);

if (false === @fwrite($this->_stream, $line)) {
try {
$result = @fwrite($this->_stream, $line);
} catch (TypeError $e) {
// require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception($e->getMessage(), $e->getCode());
}

if ($result === false) {
// require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception("Unable to write to stream");
}
Expand Down
1 change: 0 additions & 1 deletion tests/Zend/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
require_once 'Zend/Loader/AllTests.php';
require_once 'Zend/LocaleTest.php';
require_once 'Zend/Locale/AllTests.php';
require_once 'Zend/Log/AllTests.php';
require_once 'Zend/Mail/AllTests.php';
require_once 'Zend/Markup/AllTests.php';
require_once 'Zend/Measure/AllTests.php';
Expand Down
Loading