Page 1 of 1

Classes / OOP Programming error

Posted: Wed Jun 26, 2002 11:52 am
by fatal
I get this error from my that it cant find this once function, but others i call before it are fine. The error is:
Fatal error: Call to a member function on a non-object in c:\apache\apache\htdocs\testnews.php on line 41
The code for testnews:

Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<table width="502" cellspacing="0" cellpadding="0" align="center" border="1" bordercolor="#000000">
  <tr> 
    <td width="500" bordercolor="#000000" bgcolor="#6699CC">
      <blockquote>
	  <?php
	  		include_once("news_sys.php");
			#news_sys = new news_sys;
			
			switch( $p )
			&#123;
				case "comment":
					$news_sys->GetComments($ID);
					echo"
					<form name="form1" method="post" action="$PHP_SELF?p=add">
  						<p><font face="Tahoma" size="2" color="#000000">Subject: 
    						<input type="text" name="subject" value="Re: $subject">
    						<br>
							Comments: 
							<textarea name="comments" cols="25"></textarea>
							<input type="hidden" name="ID" value="$ID">
    						</font></p>
  						<p> 
    						<input type="submit" name="Submit" value="Submit">
    						<input type="reset" name="Submit2" value="Reset">
  						</p>
					</form>
					";
					break;
				case "add":
					$news_sys->InsertComment( $subject, $comments, $ID );
					$subject = $comments = $ID = "";
					break;
				default:
					$news_sys->GetNews(15);
					break;
			&#125;	
	  ?>
	  </blockquote>
    </td>
  </tr>
</table>
</body>
</html>
the particular line of error is:

Code: Select all

$news_sys->GetNews(15);
I have no idea whats going wrong, bec the other class calls are fine. Im using Apache 1.32.24, and Php 4.3.0dev

Thanks for anytype of help.

Posted: Wed Jun 26, 2002 1:38 pm
by jason
On line 14:

Code: Select all

#news_sys = new news_sys;

Posted: Wed Jun 26, 2002 5:22 pm
by fatal
when i uncomment it, i get errors for line 14.
Parse error: parse error in c:\apache\apache\htdocs\testnews.php on line 14
my class is called 'news_sys' if thats any help.

also another weird thing about it is when I make my include file not in class sturcture, just functions. It still cant find the function on line 41.

Im powerfully confused on this one.

Posted: Wed Jun 26, 2002 6:51 pm
by jason

Code: Select all

#news_sys = new news_sys;
should be changed to

Code: Select all

$news_sys = new news_sys;
You can't just uncomment it, you also have to assign it to a real variable.

Also, if you have a constructor for your class, you need to do this:

Code: Select all

$news_sys = new news_sys();
at least.

Posted: Wed Jun 26, 2002 7:09 pm
by fatal
Thanks Jason, i am now past all the errors i gotten previously. Thanks again.

Posted: Wed Jun 26, 2002 8:23 pm
by jason
What was the problem?

Posted: Thu Jun 27, 2002 12:48 am
by fatal
my stupidity :?