[development] Cleaner and more consistent code.

Wim Mostrey drupal at mostrey.be
Thu Aug 2 11:48:28 UTC 2007

I would suggest to make Drupal core use only db_fetch_object but to keep
support for db_fetch_row for contributed modules. In core it is very
confusing to see the following in node.module for instance:

function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
  $node = (object)$node;

function node_submit($node) {
  global $user;

  // Convert the node to an object, if necessary.
  $node = (object)$node;

function node_validate($node, $form = array()) {
  // Convert the node to an object, if necessary.
  $node = (object)$node;

function node_access($op, $node = NULL) {
  global $user;

  // Convert the node to an object if necessary:
  if ($op != 'create') {
    $node = (object)$node;

It would lead to more consistent code to make it best practice to always
pass a node as an object for instance.


ojacquet at jax.be wrote:
> A while ago I suggested on d.o. to remove either db_fetch_row or
> db_fetch_object. This would result in cleaner code, more consistent
> function signatures and hooks. At my current work this is included in the
> coding conventions, we only use mysql_fetch_object(). I'm posting this to
> the development mailing because I am interested in what you, as developers,
> think about this.
> The original suggestion:
> http://drupal.org/node/158115
> Example of an inconsistent hook:
> http://drupal.org/node/124141

More information about the development mailing list