From:             
Operating system: Ubuntu Linux / Windows 7
PHP version:      5.3.8
Package:          PDO related
Bug Type:         Bug
Bug description:call to empty() on NULL result using PDO::FETCH_LAZY returns 
false

Description:
------------
> PHP 5.3.8 (on both Ubuntu Linux and Windows 7)
> ./configure --with-pdo-mysql
> No changes to php.ini

When fetching rows from a MySQL database using PDO with the default fetch
method 
FETCH_LAZY, the empty() function returns false on NULL values in the
database. 
This behavior does not exist when using other fetch methods (such as
FETCH_OBJ or 
FETCH_ASSOC).

Test script:
---------------
$row = $stmt->fetch(PDO::FETCH_LAZY);

echo $row->Address2."\n";             // RIGHT: outputs ''
var_dump($row->Address2);             // RIGHT: outputs 'NULL'
var_dump(!$row->Address2);            // RIGHT: outputs 'bool(true)'
var_dump(!!$row->Address2);           // RIGHT: outputs 'bool(false)'

echo empty($row->Address2)."\n";      // WRONG: outputs ''
var_dump(empty($row->Address2));      // WRONG: outputs 'bool(false)'
var_dump(empty($row['Address2']));    // WRONG: outputs 'bool(false)'

$var = $row['Address2'];
var_dump($var);                       // RIGHT: outputs 'NULL'
var_dump(empty($var));                // RIGHT: outputs 'bool(true)'

Expected result:
----------------
NULL
bool(true)
bool(false)
1
bool(true)
bool(true)
NULL
bool(true)

Actual result:
--------------
NULL
bool(true)
bool(false)

bool(false)
bool(false)
NULL
bool(true)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=60665&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=60665&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=60665&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=60665&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=60665&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60665&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=60665&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=60665&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=60665&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=60665&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=60665&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=60665&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=60665&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=60665&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=60665&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=60665&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60665&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=60665&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=60665&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=60665&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=60665&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=60665&r=mysqlcfg

Reply via email to