Digwood Posted November 1, 2008 Share Posted November 1, 2008 I have a class that is supposed to be used to perform common tasks sitewide. My problem, is that any page that loads it, fails to find it, but then displays about half of the code to the screen from said class. The class is written into a separate .php file, so the fact that it's displaying code from my class file leads me to understand that it isn't a pathing issue. Any suggestions? Code Follows: ::From the page instantiating my class:: <?php require_once("./Scripts/cArticle.php"); require_once("./Scripts/mike.php"); if (isset($_REQUEST['error'])){ $error = $_REQUEST['error']; } else{ $error = 0; } $test = new mike($_SERVER['QUERY_STRING'], $_SERVER['SERVER_NAME'], $_SERVER['PHP_SELF'], $error, $_REQUEST['aid']); ?> ::Code from my class file:: <?php class common{ private $username = ""; private $query = ""; private $server = ""; private $self = ""; private $error = ""; private $artID = ""; private $urlcode = ""; public function common($pQuery, $pServer, $pSelf, $pError, $pArtID){ $this->$query = $pQuery; $this->$server = $pServer; $this->$self = $pSelf; $this->$error = $pError; $this->$artID = $pArtID; } public function queryStringTest(){ if (empty($this->query)){ $this->urlcode = '<input type="hidden" name="url" value="http://'.$this->server.$this->self.'" />'; } else{ $this->urlcode = '<input type="hidden" name="url" value="http://'.$this->server.$self.'?'.$this->query.'" />'; //elimiate duplicate error queries if (isset($this->error) && isset($this->artID)){ $aid = "aid=".$this->artID; $this->urlcode = "<input type='hidden' name='url' value='http://".$this->server.$this->self."?".$aid."' />"; } } } public function loginCheck(){ if (isset($_COOKIE['user']) && (!empty($_COOKIE['user']))){ echo "<div class='navbutton'"; echo "<a href='admin.php'> Admin Page </a>"; echo "</div>"; } else{ echo $this->urlcode; } } public function getUsername(){ return $this->username; } } ?> ::The Output I get:: ��$query = $pQuery; $this->$server = $pServer; $this->$self = $pSelf; $this->$error = $pError; $this->$artID = $pArtID; } public function queryStringTest(){ if (empty($this->query)){ $this->urlcode = ''; } else{ $this->urlcode = ''; //elimiate duplicate error queries if (isset($this->error) && isset($this->artID)){ $aid = "aid=".$this->artID; $this->urlcode = ""; } } } public function loginCheck(){ if (isset($_COOKIE['user']) && (!empty($_COOKIE['user']))){ echo " urlcode; } } public function getUsername(){ return $this->username; } } ?> Fatal error: Class 'mike' not found in C:\the\path\of\my\testing\server\testing.php on line 16 Any help would be appreciated Link to comment https://forums.phpfreaks.com/topic/130945-class-is-not-performing-correctly/ Share on other sites More sharing options...
Stooney Posted November 1, 2008 Share Posted November 1, 2008 Your class is called 'common' but you're trying to instantiate it using 'mike'. Change $test = new mike($_SERVER['QUERY_STRING'], $_SERVER['SERVER_NAME'], $_SERVER['PHP_SELF'], $error, $_REQUEST['aid']); to $test = new common($_SERVER['QUERY_STRING'], $_SERVER['SERVER_NAME'], $_SERVER['PHP_SELF'], $error, $_REQUEST['aid']); Link to comment https://forums.phpfreaks.com/topic/130945-class-is-not-performing-correctly/#findComment-679846 Share on other sites More sharing options...
Digwood Posted November 1, 2008 Author Share Posted November 1, 2008 Crap, sorry. I had changed everything from 'common' to 'mike' at one point to see if it was just the class name it was having trouble with. I thought I had changed them all back. I still get the same results, even with the correct class names. Sorry about the typo... Link to comment https://forums.phpfreaks.com/topic/130945-class-is-not-performing-correctly/#findComment-680020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.