Drezard Posted December 28, 2007 Share Posted December 28, 2007 Okay, I'm working with 4 main files in this problem. Very small amounts of code. Now, so far profiles.class.php is running a function (create) which requires a function (post) from another file forms.class.php which contains the class forms. Now, Im getting this error: Fatal error: Call to a member function posted() on a non-object in C:\xampp\htdocs\client\extensions\profiles.class.php on line 11 profiles.class.php: <?php require_once('extensions/forms.class.php'); $forms = new forms; class profiles { function create() { $result = $forms->post(); if ($result == false) { echo "Complete the fields marked with <span class='main-first'>*</span><span class='content'>"; echo "<table width='50%' border='0'>"; echo "<form method='post'>"; echo "<tr>"; echo "<td width='25%> Name: </td> <td> <input type='text' name='name'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Email: </td> <td> <input type='text' name='email'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Address: </td> <td> <input type='text' name='address'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Postcode: </td> <td> <input type='text' name='postcode'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Suburb: </td> <td> <input type='text' name='suburb'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Phone Number: </td> <td> <input type='text' name='phone'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Mobile: </td> <td> <input type='text' name='mobile'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%'> <input type='submit' name='submit'> </td> <td> </td>"; echo "</tr>"; echo "</form>"; echo "</table>"; } } } ?> forms.class.php: <?php class forms { function post() { if (isset($_POST['submit'])) { return true; } else { return false; } } function check($value) { if (trim($value) == '') { return false; } else { return true; } } } ?> header.inc.php: <?php require_once('extensions/profiles.class.php'); $profiles = new profiles; ?> <html> <head> <title> Wintersword Studios </title> <link rel="stylesheet" type="text/css" href="extensions/styles/style.css" /> </head> <body> <table width='100%' border="0" class='layout'> <tr> <td> <table width="100%" border="0"> <tr> <td width='50%' valign='bottom'><span class='title-first'>C</span><span class='title'>MS v1.0</span></td> <td valign='bottom'> <a href='index.php' style="text-decoration:none;"> <span class='main-first'>H</span><span class='main'>ome </span></a> <span class='main'> | </span><a href='terms.php' style='text-decoration:none;'><span class='main-first'>T</span><span class='main'>erms</span></a><span class='main'> | </span><a href='sitemap.php' style='text-decoration:none;'><span class='main-first'>S</span><span class='main'>itemap</span></a><span class='main'> | </span><a href='support.php' style='text-decoration:none;'><span class='main-first'>S</span><span class='main'>itemap</span></a></td> </tr> </table> <table width="100%" border="0"> <tr> <td> </td> </tr> </table> <table width="100%" border="0" cellpadding='5px'> <tr> <td width='22%' class='middle'> <span class='content'> Links: </span></td> <td> <span class='content'> index.php: <?php require_once('extensions/templates/header.inc.php'); ?> Welcome to Wintersword's CMS. This site is currently version 1.0-Beta. CMS or Client Management System is used to keep track of information in an ordered and easy to access way. It is mainly used for monitoring entitie's clients but, it can be used for many other things. <br /> <br /> Features: <br /> - Creation and manipulation of records <br /> - User permissions <br /> - Search functions <br /> Bugs fixed: <br /> - None <br /> <?php require_once('extensions/templates/footer.inc.php'); ?> Yeap, thats about all the information I can give without being a bore. Can you please help me with whats wrong? Daniel Quote Link to comment https://forums.phpfreaks.com/topic/83444-php5-oop-problems/ Share on other sites More sharing options...
trq Posted December 28, 2007 Share Posted December 28, 2007 The object $forms does not exist within the class profiles. You need to define it within the class itself, no good defining it outside because it is out of scope. eg; <?php class forms{} class profile { private $forms; function __construct() { $this->forms = new forms; // now the forms object can be accessed within the profile class using $this->forms. } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83444-php5-oop-problems/#findComment-424521 Share on other sites More sharing options...
Drezard Posted December 28, 2007 Author Share Posted December 28, 2007 Same error, Different line. New code for profiles.class.php: <?php require_once('extensions/forms.class.php'); class profiles { private $forms; function __construct() { $this->forms = new forms; } function create() { $result = $forms->post(); if ($result == false) { echo "Complete the fields marked with <span class='main-first'>*</span><span class='content'>"; echo "<table width='50%' border='0'>"; echo "<form method='post'>"; echo "<tr>"; echo "<td width='25%> Name: </td> <td> <input type='text' name='name'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Email: </td> <td> <input type='text' name='email'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Address: </td> <td> <input type='text' name='address'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Postcode: </td> <td> <input type='text' name='postcode'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Suburb: </td> <td> <input type='text' name='suburb'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Phone Number: </td> <td> <input type='text' name='phone'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%> Mobile: </td> <td> <input type='text' name='mobile'> </td>"; echo "</tr>"; echo "<tr>"; echo "<td width='25%'> <input type='submit' name='submit'> </td> <td> </td>"; echo "</tr>"; echo "</form>"; echo "</table>"; } } } ?> Thanks, Daniel Quote Link to comment https://forums.phpfreaks.com/topic/83444-php5-oop-problems/#findComment-424527 Share on other sites More sharing options...
Jenk Posted December 28, 2007 Share Posted December 28, 2007 use $this->forms , not $forms within the create method. Quote Link to comment https://forums.phpfreaks.com/topic/83444-php5-oop-problems/#findComment-424538 Share on other sites More sharing options...
448191 Posted December 28, 2007 Share Posted December 28, 2007 You obviously haven't got your basics covered. Try a OOP tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/83444-php5-oop-problems/#findComment-424769 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.