requiring a class... twice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

requiring a class... twice

Post 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"
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

require :arrow: require_once
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 =]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply