com php-src: Fix #60665: call to empty() on NULL result using PDO::FETCH_LAZY returns false: NEWS ext/pdo/pdo _stmt.c ext/pdo/tests/bug_60665.phpt

From: Date: Fri, 12 Aug 2016 23:11:13 +0000
Subject: com php-src: Fix #60665: call to empty() on NULL result using PDO::FETCH_LAZY returns false: NEWS ext/pdo/pdo _stmt.c ext/pdo/tests/bug_60665.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-93765@lists.php.net to get a copy of this message
Commit: 7938ebf6c1b302d3d1b1bfb798f1cf6f07e1e178 Author: Christoph M. Becker <cmbecker69@gmx.de> Sat, 13 Aug 2016 00:31:55 +0200 Parents: f19578ad58d7ae82f16afd282e1c600927b106a2 Branches: PHP-5.6 PHP-7..0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7938ebf6c1b302d3d1b1bfb798f1cf6f07e1e178 Log: Fix #60665: call to empty() on NULL result using PDO::FETCH_LAZY returns false The has_property handler only checked whether a respective column name exists, but neither whether the column value is set, nor whether it is empty, respectively. We fix that to match the behavior of POD:FETCH_OBJ in particular and PHP in general. Bugs: https://bugs.php.net/60665 Changed paths: M NEWS M ext/pdo/pdo_stmt.c A ext/pdo/tests/bug_60665.phpt Diff: diff --git a/NEWS b/NEWS index 10f0302..90215cd 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ PHP NEWS - MSSQL: . Fixed bug #72039 (Use of uninitialised value on mssql_guid_string). (Kalle) +- PDO: + . Fixed bug #60665 (call to empty() on NULL result using PDO::FETCH_LAZY + returns false). (cmb) + 18 Aug 2016, PHP 5.6.25 - Core: diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index a2ae2fd..f5c295c 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -2623,7 +2623,15 @@ static int row_prop_exists(zval *object, zval *member, int check_empty, const ze * numbers */ for (colno = 0; colno < stmt->column_count; colno++) { if (strcmp(stmt->columns[colno].name, Z_STRVAL_P(member)) == 0) { - return 1; + int res; + zval *val; + + MAKE_STD_ZVAL(val); + fetch_value(stmt, val, colno, NULL TSRMLS_CC); + res = check_empty ? i_zend_is_true(val) : Z_TYPE_P(val) != IS_NULL; + zval_ptr_dtor(&val); + + return res; } } } diff --git a/ext/pdo/tests/bug_60665.phpt b/ext/pdo/tests/bug_60665.phpt new file mode 100644 index 0000000...28c1482 --- /dev/null +++ b/ext/pdo/tests/bug_60665.phpt @@ -0,0 +1,41 @@ +--TEST-- +PDO Common: Bug #60665 (call to empty() on NULL result using PDO::FETCH_LAZY returns false) +--SKIPIF-- +<?php +if (!extension_loaded('pdo')) die('skip'); +$dir = getenv('REDIR_TEST_DIR'); +if (false == $dir) die('skip no driver'); +require_once $dir . 'pdo_test.inc'; +PDOTest::skip(); +?> +--FILE-- +<?php +if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/'); +require_once getenv('REDIR_TEST_DIR') . 'pdo_test..inc'; +$db = PDOTest::factory(); + +$statement = $db->prepare("SELECT NULL AS null_value, 0 AS zero, 1 AS one"); +$statement->execute(); +$row = $statement->fetch(PDO::FETCH_LAZY); +var_dump( + empty($row->null_value), + empty($row->zero), + !empty($row->one), + empty($row->missing), + !isset($row->null_value), + isset($row->zero), + isset($row->one), + !isset($row->missing) +); +?> +===DONE=== +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +===DONE===

« previous php.cvs (#93765) next »