Class name must be a valid object or a string

I am receiving the above error message in one of my PHP Scripts and wondered if somebody could give me a clue as to what it means…

The file path it gives me at the end of the error message leads me to a piece of code that, as far as I can tell, contains no class names. That code is here:

// -------------------------------------------------------------------------------------------------
// INCLUDES AND SETUP
// -------------------------------------------------------------------------------------------------
$phpEx = 'php';
$phpbb_root_path = get_option( 'wp2bb_phpbbpath' ) . '/';
$host = get_option( 'wp2bb_wpurl' );
$username=get_option( 'wp2bb_username' );
$usercolour=get_option( 'wp2bb_usercolor' );

include("wp2bbforum.php");
include("wp2bbadmin.php");

if (file_exists($phpbb_root_path . '/config.php')) {
  $db = new $sql_db();
  $cache = new cache();
}

The line number the error message refers to, within the above piece of code, corresponds to the line that says:

$db = new $sql_db();

Can anyone point me in the right direction to troubleshoot this script?

The variable $sql_db should likely have been set in one of those include files.

It would probably be something like “Mysql” so that call would become:


$db = new Mysql();

vs something like SQLServer() or PostGres()

You had better check those include files - which in turn could have include files of their own.

Most likely candidate looks like config.php :wink:

The variable $sql_db should be set by phpBB, but for some reason it doesn’t look like it is. Are you are all of the files are in the correct place? Try seeing where [COLOR="DarkRed"]$phpbb_root_path . 'includes/db/dbal.php'[/COLOR] is (echo() it) and see if that file exists?

You could hard-code the class name (probably dbal_mysql) but it’s probably best to get the variable loaded properly.