Page 1 of 1

Annoyed newbie HTTP 500 Internal Server Error

Posted: Thu Jul 01, 2010 5:58 am
by sunegtheoverlord
Hi guys and gals,

I'm following this tutorial on OOPHP http://www.killerphp.com/tutorials/object-oriented-php/

how come i get an HTTP 500 Internal Server Error when trying to run this code

Code: Select all

		<?php include("class_lib.php"); ?>
	</head>
	<body>
		<?php
			 $stefan = new person();
			 $jimmy = new person;
			 
			 $stefan->set_name("Stefan Mischook");
			 $jimmy->set_name("Nick Waddles");
			
			echo "Stefan's full name: " . $stefan->get_name();
			echo "Nick's full name: " . $jimmy->get_name(); 
		?>
		
	</body>
</html> 
when i change it to this

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html;
		charset=iso-8859-1" />

		<title>OOP in PHP</title>
		<?php include ("class_lib.php"); ?>
</head>
<body>
<?php
echo "hello";
?>
</body>		

</html>
It displays "hello" fine.

What am i missing? I'm using 5.2.8.
Ta

S

Re: Annoyed newbie HTTP 500 Internal Server Error

Posted: Thu Jul 01, 2010 7:08 am
by internet-solution
Is your error_reporting on?

If not, stick the following at top of your page and see what errors are displayed

Code: Select all

<?php
 error_reporting(E_ALL);
 ini_set("display_errors", 1);
?>

Re: Annoyed newbie HTTP 500 Internal Server Error

Posted: Thu Jul 01, 2010 8:11 am
by Benjamin
I think the person constructor is calling the set_name method, which is then calling itself statically in a loop. Maybe you used = rather than == in the if/else conditional.

Re: Annoyed newbie HTTP 500 Internal Server Error

Posted: Thu Jul 01, 2010 8:27 am
by mikosiko
the second part that you posted is working because you are not doing anything (other than include the file) with the class (or classes/functions) that you defined in your class_lib.php file.

Post the code that you have in your class_lib.php to try to identify your problem.

Re: Annoyed newbie HTTP 500 Internal Server Error

Posted: Thu Jul 01, 2010 8:49 am
by sunegtheoverlord
Hello again,

Thanks for the replies, the code in class_lib.php is

Code: Select all

<?php 
class person {
	var $name; 
	function set_name($new_name) { 
		$this->name = $new_name;  
 	}

   function get_name() {
		return $this->name;
	}
} 
?>
any more help?

Re: Annoyed newbie HTTP 500 Internal Server Error

Posted: Thu Jul 01, 2010 8:52 am
by sunegtheoverlord
By the way i put on error reporting as suggested.

I get the following error

Notice: Undefined variable: stephan in /usr/home/toby/enquiries/htdocs/OO/index1.php on line 23

Fatal error: Call to a member function get_name() on a non-object in /usr/home/toby/enquiries/htdocs/OO/index1.php on line 23

Re: Annoyed newbie HTTP 500 Internal Server Error

Posted: Thu Jul 01, 2010 8:55 am
by sunegtheoverlord
Sorry guys,

worked it out, i mispelled "Stefan" on line 21.....

"*£(!"£*($&*(&¬!

Thanks for all your time and help anyway.

S

Re: Annoyed newbie HTTP 500 Internal Server Error

Posted: Thu Jul 01, 2010 8:59 am
by Jade
For some reason it doesn't think $stefan is a person object. I also noticed you're missing () behind the person class for your $jimmy variable.

Have you tried doing:

Code: Select all

                <?php include("class_lib.php"); ?>
        </head>
        <body>
                <?php
                         $stefan = new person();
                         $stefan->set_name("Stefan Mischook");
                         print_r($stefan); //print out the values of stefan and make sure it shows it as a [person] object with a [name] => Stefan Mischook
                       
                        echo "Stefan's full name: " . $stefan->get_name();
                ?>
               
        </body>
</html>