February 22, 200818 yr Ok I have a class in the format of: class Code{ .... function getName(){ $val = 'Test'; return $val; } function getOtherName(){ $val = 'Test'; return $val; } } Then I use this class on another page like this: $code = new Code(); $value = $code->getName(); Which works fine, but when I add: $anotherval = $code->getOtherName(); underneath it comes up with this error: Call to a member function on a non-object in /var/www/.../code.php on line 3 I mean why?! I use classes all the time, what's so abnormal about this? What am I missing?! It's got to be something so stupid!
February 22, 200818 yr Author And to confuse matters even more confusing if I do: $code = new Code(); $anotherval = $code->getOtherName(); $value = $code->getName(); It seems to work fine! Have I been missing a basic rule of PHP all these years or something?
February 22, 200818 yr Nothing wrong with that, works for me. There must be more to it, can you paste your entire code?
February 22, 200818 yr Author code.php $code = new Code(); $code->retrieveCodeInfo($codeid); $ven = $code->venue(); $id = ' '; $name = $code->getCourseName(); code.inc.php require_once("database.inc.php"); class Code { var $codeid; var $loc; var $courseid; var $code; var $occur; var $sdate; var $edate; var $hrswk; var $numwks; var $daytime; var $tutor; var $active; var $vp; var $drop; function retrieveCodeInfo($id){ $this->codeid = $id; $sql = "SELECT * FROM Course WHERE id = '$this->codeid'"; $dbconn = new Database(); $result = $dbconn->getQueryResults($sql); $row = mysql_fetch_array($result); $this->loc = $row['Location_code']; $this->courseid = $row['course_id']; $this->code = $row['code']; $this->occur = $row['occur']; $this->sdate = $row['start_date']; $this->edate = $row['end_date']; $this->hrswk = $row['hours_week']; $this->numwks = $row['num_weeks']; $this->daytime = $row['day_times']; $this->tutor = $row['tutor']; $this->active = $row['active']; $this->vp = $row['vp_validated']; $this->drop = $row['dropin']; } function getCourse(){ $val = 'Test'; return $val; } function getCourseName(){ $tip = 'Test'; return $tip; } function getCode($mode='edit'){ if($mode == 'edit'){ $val = '<input name="code" type="text" value="'.$this->code.'" />'; }else{ $val = $this->code; } return $val; } function venue(){ $val = 'please work'; return $val; } }
February 22, 200818 yr Author Its in code.php $code = new Code(); $code->retrieveCodeInfo($codeid); $ven = $code->venue(); $id = ' '; $name = $code->getCourseName(); The problem happens when i put $ven underneath $name
February 22, 200818 yr Author Would Server settings have any effect to this? We had a power cut last night and our server restarted. That wouldn't be causing this strange behavoir would it?
February 22, 200818 yr Author When I put in: error_reporting(E_ALL); Still just comes up with: Fatal error: Call to a member function on a non-object in Thanks for your thoughts, i do appreciate it...
February 22, 200818 yr Author print_r( $code ); Doesn't pull back anything when the error is showing, but when i put it the way that will display it properly (by reordering the lines again) it just displayed the value that is pulled from the database. Would any server settings what so ever have an effect on this? Because I really confuzzled...
February 22, 200818 yr Not that I can think of. Why would rebooting a server cause its settings to change?
February 22, 200818 yr What version of PHP do you have? If you haven't got the latest then try updating if possible incase it's some random PHP bug.
March 7, 200818 yr Hey man Try testing it under different environments. I replicated your code and it works fine for me. Interesting problem though
Create an account or sign in to comment