php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36851 Documentation and code discrepancies for NULL data
Submitted: 2006-03-24 22:13 UTC Modified: 2006-03-28 11:13 UTC
From: cjbj at hotmail dot com Assigned: tony2001 (profile)
Status: Closed Package: OCI8 related
PHP Version: 5.1.2 OS: Linux
Private report: No CVE-ID: None
 [2006-03-24 22:13 UTC] cjbj at hotmail dot com
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"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-28 11:13 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 08:01:28 2024 UTC