PHP Classes

The class has issues

Recommend this page to a friend!

      DBF Class  >  All threads  >  The class has issues  >  (Un) Subscribe thread alerts  
Subject:The class has issues
Summary:Some problems I found with dbf_class.php
Author:Larry Wakeman
Date:2009-11-21 22:19:35

  1. The class has issues   Reply   Report abuse  
Larry Wakeman - 2009-11-21 22:19:35
I am trying to import over 150 dbf files into a MySQL database so I have some things that I would prefer.

First, the constructor has exit statements on errors. For a class near the bottom of the stack, this is not a good idea. It is better to report the error to the creator of the object and let that script decide if the error is fatal. There are two ways to handle this, the first and probably better, would be to create an empty constructor, i.e.:

function dbf_class() {

and to put all of the current constructor codes in another function such as open. Then this function could return true for success in opening the file and false on failure.

What I did, it works, was to create an error attribute:

var $error; // Error message on failure

and change the error trappings to something like:

if ( !file_exists($filename)) {
$this->error = 'Error - Not a valid DBF file !!!';

After calling the constructor, I check to see if the error attribute is empty or not. It should be initialized at the beginning of the constructor:

$this->error = "";

The second issue is when you are checking for a valid dbf file, you use the following statement:

if(!(ord($this->_raw[0]) == 3 || ord($this->_raw[0]) == 131) && ord($this->_raw[$filesize]) != 26) {

The first issue with this is that if the file is trunated, $this->_raw[$filesize] is not set and throws an error. You should check for it and initialize it (to 0 works) if it is not set. You are also not checking for dBase level 7.

That is all for now, Good Work.