PHP Class (class not defined)

Hello,

I have been creating a website the last few weeks and I have a Linux Debian Ubuntu 12.x Server @ my home.
That is where i have been developing the website on. Everything works and is fine…

Now when I upload it to a webserver it runs a few functions inside my class and after a few it just quits the class and it says that the class doesn’t exists…
When I include the class at the top then it tells me that another class is missing.

I have been searching for hours and hours and I just can’t find a way to solve it…

Here is the website not working website: http://beta.robrotgersfotografie.nl
Here is the working website: http://larsrotgers.nl/~rrf

Both URLS are the same website…

The strangest thing is that the whole website works except for the portfolio page…
And the referenties (references) page uses exactly the same method as I use for my portfolio page and that one does work…

Here is some code:

My portfolio.class.php

[php]<?php

class portfolio extends main {

	// Define globals
	static $category;
	static $categories;
	static $cat;
	
	// Get category Id that has to be loaded.
	function getCategory() {
		
		if(portfolio::$cat[$_GET['c']]['name']) {
			portfolio::$category = $_GET['c'];
		}
		else {
			portfolio::$category = 0;
		}
		
	}
	
	// Load the menu.
	function loadMenu() {
		include 'portfolio/menu.php';
	}
	
	
	// Define all the categories.
	function setCategories() {
		
		// Set directory of the portfolio folder.
		$directory = "portfolio/";
		// Load dir
		$dir = dir($directory);
		// Loop through the folder
		while(($file = $dir->read()) !== false) {
			// Explode file name
			list($fileName, $ext) = explode(".", $file);
			// If the file name has more that 0 characters and there is no extension
			if(strlen($fileName) > 0 && !$ext) {
				// Load name into the $categories global
				portfolio::$categories[] = $fileName;
			}
		}
		// Close dir	
		$dir->close();
	}
	
	// Load category data and set array variables.
	function loadCategories() {
		// Sort all the categories alphabetic
		sort(portfolio::$categories);
		
		// Loop all global $categories
		foreach(portfolio::$categories as $id=>$name) {
			// Set global variables for $cat
			portfolio::$cat[$id]['id'] = $id;
			portfolio::$cat[$id]['name'] = $name;
			portfolio::$cat[$id]['active'] = "";
		}
	}
	
	// Load all photos and show them on the webpage.
	function loadPhotos($folder) {
		// Set folder data for JQ
		echo "<div id="folder">portfolio/".$folder."/</div>";
		// Load dir
		$dir = dir("portfolio/".$folder."/");
		$id = 0;
		// Loop through folder
		while(($file = $dir->read()) !== false) {
			
			$arrImages[] = list($fileName, $ext) = explode(".", $file);
			
		}
		
		sort($arrImages);
		
		//print_r($arrImages);
		
		foreach($arrImages as $img=>$key) {
		
			if($key[1] == "jpg") {
				echo '<div class="thumb"><img src="portfolio/'.$folder.'/thumbs/'.ereg_replace(" ", "%20", $key[0]).'.'.$key[1].'" alt="'.$key[0].'" onclick="pfGoto('.$id.');"/></div>';
				$id++;
			}
			
		}
		
	}
	
	// Photo Viewer
	function photoViewer() {
		
		if(page::$p_name == "portfolio") {
			include 'html/photoViewer/photoViewer.html';
		}
		
	}
	
	function hideFooter() {
		if(page::$p_name == "portfolio") {
			echo '
			
				<script type="text/javascript">
					$( function() {
						$(".logo, .slogan").remove();
						$(".extras .portfolio").remove();
					});
				</script>
			
			';
		}
	}
	
	function getInformation($catId) {
		include "portfolio/text_". $catId .".txt";
	}

}

?>[/php]

My portfolio.php

[php]<?php
portfolio::setCategories();
portfolio::loadCategories();
portfolio::getCategory();

?>

<?php portfolio::loadMenu(); ?>
1
<?php portfolio::loadPhotos(portfolio::$cat[portfolio::$category]['name']); ?>
<?php echo portfolio::getInformation(portfolio::$category); ?>
Vergootte foto...
[/php]

Also I have been programming for PHP like 3 years… And never had I messy problem like these but I just can’t figure it out.
Hope that someone can help me.

Best regards,

L. Rotgers

class not defined should be: class not found

My mistake… :wink:

Have you tried not calling them statically? I’m not sure if this will help, but I see a ton of problems with this code.

[php]
$portfolio = new portfolio();
$portfolio->setCategories();
$portfolio->loadCategories();
$portfolio->getCategory();
[/php]

Hey,

Thanks for your reply but I have already tried to load it that way, then I get the error that another class is missing… I just don’t get it because it is working at my own webserver. Although on the webhost it isn’t working… I think it has something to do with a config file for the webserver? PHP version?

And my reference page uses almost the same method to load like ~30 images in a folder and generate a page out if it. And that one is working.

Also when I try this in a few other methods I get the error at the dir() command.

$dir->read();

But I will try your method and post the result :wink:

Thanks for your reply

The result is the same as if I was using the [i]scope resolution operator /i.

Notice: Undefined offset: 1 in /public/sites/beta.robrotgersfotografie.nl/classes/portfolio.class.php on line 38

Notice: Undefined offset: 1 in /public/sites/beta.robrotgersfotografie.nl/classes/portfolio.class.php on line 38

Notice: Undefined index: c in /public/sites/beta.robrotgersfotografie.nl/classes/portfolio.class.php on line 13

Notice: Undefined index: in /public/sites/beta.robrotgersfotografie.nl/classes/portfolio.class.php on line 13

Fatal error: Class 'portfolio' not found in /public/sites/beta.robrotgersfotografie.nl/portfolio/portfolio.php on line 3

::slight_smile: => ::

Also all my classes are loaded at the index.php file that calls my libraries.php (which contains all the includes for my classes).

From there it calls that class page that will direct you to the correct page that has to be shown.

These modules are used on every page to guide you through the website. Except for the portfolio there it stopped working. And as I specified above it does work on my own webserver but not on a online webhost.

Really hoping to fix this ;D

In the portfolio class, I would try changing all internal references from portfolio to self.

For example

portfolio::$categories to self::$categories

Note: You would only do this inside the portfolio class iteself, not in your portfolio.php file.

No it already has been loaded before, however if I include this class again then it couldn’t find my page class…

But my index loads all my classes from there the page includes all my page’s that are shown…

As you can see in the error on line 34 in the portfolio class it performs an action and after that the class couldn’t be found anymore… like it dissapeared.

And if I go through command by command the one that causes it is the dir(); command. But on the reference page I also am using this command and there it works. Also if I echo all the dirs in the portfolio it will show them but upoad making the menu I get the class not found error…

changed all portfolio:: to self:: but I still get the same error… :frowning:

I wasn’t able to duplicate the problem on my own. You do have a syntax error which I’m not sure why it doesn’t appear on your output.

[php]
echo “

portfolio/”.$folder."/
";
[/php]

Needs to be

[php]
echo “<div id=“folder”>portfolio/”.$folder."/";
[/php]

[php]
// Load all photos and show them on the webpage.
function loadPhotos($folder) {
// Set folder data for JQ
echo “<div id=“folder”>portfolio/”.$folder."/";
// Load dir
$dir = dir(“portfolio/”.$folder."/");
$id = 0;
// Loop through folder
while(($file = $dir->read()) !== false) {

			$arrImages[] = list($fileName, $ext) = explode(".", $file);
			
		}
		
		sort($arrImages);
		
		//print_r($arrImages);
		
		foreach($arrImages as $img=>$key) {
		
			if($key[1] == "jpg") {
				echo '<div class="thumb"><img src="portfolio/'.$folder.'/thumbs/'.ereg_replace(" ", "%20", $key[0]).'.'.$key[1].'" alt="'.$key[0].'" onclick="pfGoto('.$id.');"/></div>';
				$id++;
			}
			
		}
		
	}

[/php]

:smiley: Thanks, but that doesn’t cause the problem :frowning:

I don’t think it is something in the code because on my own webserver it works perfect :slight_smile: but on the webhost (other server, other php setup etc) I get an error…

also no I have tried to load all the functions into the portfolio.php with this as result:

[php]

<?php // Set directory of the portfolio folder. $directory = "/public/sites/beta.robrotgersfotografie.nl/portfolio/"; // Load dir $dir = dir($directory); // Loop through the folder while(($file = $dir->read()) !== false) { // Explode file name list($fileName, $ext) = explode(".", $file); // If the file name has more that 0 characters and there is no extension if(strlen($fileName) > 0 && !$ext) { // Load name into the $categories global $categories[] = $fileName; } } // Close dir $dir->close(); // Sort all the categories alphabetic sort($categories); // Loop all global $categories foreach($categories as $id=>$name) { // Set global variables for $cat $cat[$id]['id'] = $id; $cat[$id]['name'] = $name; $cat[$id]['active'] = ""; } if($cat[$_GET['c']]['name']) { $category = $_GET['c']; } else { $category = 0; } ?>
<?php include 'menu.php'; ?>
1
<?php
			$folder = $cat[$category]['name'];
			// Set folder data for JQ
			echo "<div id=\"folder\">portfolio/".$folder."/</div>";
			// Load dir
			$dir = dir($folder."/");
			$id = 0;
			// Loop through folder
			while(($file = $dir->read()) !== false) {
				
				$arrImages[] = list($fileName, $ext) = explode(".", $file);
				
			}
			
			sort($arrImages);
			
			//print_r($arrImages);
			
			foreach($arrImages as $img=>$key) {
			
				if($key[1] == "jpg") {
					echo '<div class="thumb"><img src="portfolio/'.$folder.'/thumbs/'.str_replace(" ", "%20", $key[0]).'.'.$key[1].'" alt="'.$key[0].'" onclick="pfGoto('.$id.');"/></div>';
					$id++;
				}
				
			}
			
			
			?>
		</div>
	</div>
	<div class="controls">
		<div class="arrow left" id="prev">
			<div class="bg"></div>
			<div class="hover"></div>
		</div>
		<div class="arrow right" id="next">
			<div class="bg"></div>
			<div class="hover"></div>
		</div>
	</div>
	<div class="information">
		<div class="background"></div>
		<div class="text">
		<?php include "portfolio/text_". $category .".txt"; ?>
		</div>
		<div class="trigger">
			<div class="hover"></div>
		</div>
		<div class="trigger2"></div>
	</div>
</div>
<div class="overlay">
	<div class="background"></div>
	<div class="photo">
		<img id="pvFoto" alt="Vergootte foto..." src="geenimg.png"/>
	</div>
</div>
[/php]

Now I don’t get the error but my whole javascript is down… :frowning:

Here is a working link of my website on my own webserver: http://larsrotgers.nl/~rrf
and there is what I have now on the webhost http://beta.robrotgersfotografie.nl

Thanks for the help anyway :wink:

Anyone a suggestion? ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service