From:             cjbj at hotmail dot com
Operating system: Linux
PHP version:      5.1.2
PHP Bug Type:     OCI8 related
Bug description:  Documentation and code discrepancies for NULL data

Description:
------------
Doc bug 1: oci_fetch_array(). The manual
http://www.php.net/manual/en/function.oci-fetch-array.php says

   oci_fetch_array() returns an array with both associative and
   numeric indices.

      Note: This function sets NULL fields to PHP NULL value.

My testing shows the default does not return NULLs.  The above Note
should be removed from the documentation.

The manual later says that OCI_RETURN_NULLS is an option.  Using this
does return NULLs as expected.

Code bug 1: oci_fetch_assoc documentation says "Note: This function
sets NULL fields to PHP NULL value."  This is not true.  I'd treat
this as a code bug, since it makes it hard to code in some styles -
you have to code special case checks for each column since no entry
may exist.  Also there are no optional parameters to alter the
behavior.

Code bug 2: oci_fetch_object: same problem as oci_fetch_assoc.

Code bug 3: oci_fetch_row: same problem as oci_fetch_assoc.

Only oci_fetch_all() honors the documentation and returns NULLs.


Reproduce code:
---------------
<?php

echo "<pre>";

$c = oci_connect("hr", "hr", "//localhost/XE");

$stid = oci_parse($c, "select 'abc', null, 'ghi' from dual");

echo "Fetch All\n";
oci_execute($stid, OCI_DEFAULT);
oci_fetch_all($stid, $res);
var_dump($res);

echo "Fetch as Array\n";
oci_execute($stid, OCI_DEFAULT);
$res = oci_fetch_array($stid);
var_dump($res);

echo "Associative Array\n";
oci_execute($stid, OCI_DEFAULT);
$res = oci_fetch_assoc($stid);
var_dump($res);

echo "Object\n";
oci_execute($stid, OCI_DEFAULT);
$res = oci_fetch_object($stid);
var_dump($res);

echo "Numeric Array\n";
oci_execute($stid, OCI_DEFAULT);
$res = oci_fetch_row($stid);
var_dump($res);

oci_close($c);

echo "</pre>";

?>


Actual result:
--------------
Fetch All
array(3) {
  ["'ABC'"]=>
  array(1) {
    [0]=>
    string(3) "abc"
  }
  ["NULL"]=>
  array(1) {
    [0]=>
    NULL
  }
  ["'GHI'"]=>
  array(1) {
    [0]=>
    string(3) "ghi"
  }
}
Fetch as Array
array(4) {
  [0]=>
  string(3) "abc"
  ["'ABC'"]=>
  string(3) "abc"
  [2]=>
  string(3) "ghi"
  ["'GHI'"]=>
  string(3) "ghi"
}
Associative Array
array(2) {
  ["'ABC'"]=>
  string(3) "abc"
  ["'GHI'"]=>
  string(3) "ghi"
}
Object
object(stdClass)#1 (2) {
  ["'ABC'"]=>
  string(3) "abc"
  ["'GHI'"]=>
  string(3) "ghi"
}
Numeric Array
array(2) {
  [0]=>
  string(3) "abc"
  [2]=>
  string(3) "ghi"
}


-- 
Edit bug report at http://bugs.php.net/?id=36851&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36851&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36851&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36851&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36851&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36851&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36851&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36851&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36851&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36851&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36851&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36851&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36851&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36851&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36851&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36851&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36851&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36851&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36851&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36851&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36851&r=mysqlcfg

Reply via email to