Page 1 of 1

requiring a class... twice

Posted: Wed Feb 01, 2006 10:12 am
by s.dot
I have a function that calls a class inside of it, and I need to run this function twice
my code looks like this

Code: Select all

$message1 = $this->readyMessage($message);
$message2 = $this->readyMessage($prevMessage);
and my readyMessage() function looks like this

Code: Select all

function readyMessage($message){
     require 'class/user.common.class.php';
     $common = new common;
     $message = $common->make_clickable($common->replaceSmilies(stripslashes(nl2br(htmlentities($message,ENT_QUOTES)))));
     return $message;
}
If I run the code like this I get the error "Cannot redeclare class"
If I require the class outside of the function I get "call to a member function on a non-object"

Posted: Wed Feb 01, 2006 10:33 am
by feyd
require :arrow: require_once

Posted: Wed Feb 01, 2006 10:46 am
by s.dot
ah.

I've even used that before. I just didn't know there was a useful application of that over 'require'. Now I know. Thanks =]