Page 1 of 1

[SOLVED] tutorial script with classes problem

Posted: Tue Jun 15, 2004 11:02 pm
by John Cartwright
Okay this doesn't make any sense.. my serv been acting all wacked out today.. but ehres my problem..

I am making a tutorial script and I cannot get my function to work.. heres the error on tutorial.php
Fatal error: Cannot instantiate non-existent class: phphighlight in C:\apache2triad\htdocs\jcartonline.com\html\tutorial.php on line 2
heres tutorial.php so far

Code: Select all

<?php

$tutorials = new phphighlight;

$result = @mysql_query("SELECT * FROM tutorials_php") or die('Error performing query: '. mysql_error());	


	$row = mysql_fetch_array($result);
	
	$code = $row["code"];
	
		$tutorials->phphighlight($code); 

?>
and heres the relevant part of functions.php

Code: Select all

<?php
class tutorials {

				function phphighlight($code)
					{
					$code = "<?php\n".$code."\n?>";
    				$code = stripslashes($code);
    				$code = highlight_string($code, true);
    				$code = explode('<br />', $code);
   	
					echo $code;
					}
				}

?>
No matter what I try it never works :(

Posted: Tue Jun 15, 2004 11:05 pm
by markl999
phphighlight is a class method, not a class. You should be doing:
$tutorials =& new tutorials(); (don't need the & if using PHP5)

Posted: Tue Jun 15, 2004 11:08 pm
by John Cartwright
i have another part of my site doing the exact same thing tho..

Code: Select all

<?php
$pager = new pager; 

$pager->getpage($_GET["p"]); 

?>
and once again functions.php

Code: Select all

<?php

class pager {
	        
			function getpage($page)
				{
				if (empty($page))
					{
					$page = "home";
					}
		
				$page = $page.".php";
				include $page;
				}
			}
?>
this works perfectly

Posted: Tue Jun 15, 2004 11:09 pm
by markl999
Yeah, cause that is correct. In your first example you do:
$tutorials = new phphighlight;
But the class is called tutorials, not phphighlight.

Your first example is like doing this for the second example:
$pager = new getpage;

Which would be wrong and give you the same error as the first example :o

Posted: Tue Jun 15, 2004 11:10 pm
by John Cartwright
oh man.. thats what you get for coding for hours on end :)

thanks mark