Hello,
I am wondering if anyone could provide some help on a task I am trying to work on. However, I am being stopped by an error that states:
fatal error: Call to a member function on a non-object in /www/student/mherr170/Project2/SunInfo.php
and the line that is refers to is:
$temp2->setRise($second);
Now I have googled this error many times, but no example or explanation seems to help me fully. Here is a simple version of my code:
<?php
$monthVect = array();
class Day
{
var $sunrise;
var $sunset;
function Day()
{
$sunrise = "lll";
$sunset = "asd";
}
function getRise()
{
return $sunrise;
}
function setRise($rise)
{
$sunrise = $rise;
}
function getSet()
{
return $sunset;
}
function setSet($set)
{
$sunset = $set;
}
}//end of Day class
class Month
{
var $dayVect;// = array();
var $D;
function Month($days)
{
$dayVect = array();
for($i = 0; $i < $days; $i++)
{
$D = new Day;
//$dayVect[] = $D;
array_push($dayVect,$D);
}
}
}//end of Month class
function initVect()
{
$Janm = new Month(31);
monthVect[] = $Janm;
**Repeated 11 more times for the 11 months**
}
initVect();
readIn();
function readIn()
{
$count = 0;
$month = 0;
$day = 0;
$file=fopen("kutztown.txt","r") or exit("Unable to open file!");
while(!feof($file))
{
if($count < 9)
{
fgets($file);
}
if($count >= 9 && $count <= 38)
{
$month = 0;
$t = fgets($file);
$first = strtok($t," ");
$second = strtok(" ");
while($second !== false && $first !== false)
{
$temp2 = $monthVect[$month]->$dayVect[$day];
$temp2->setRise($second); // THIS LINE ERRORS
$second = strtok(" ");
$month++;
}
$day++;
}
if($count > 40)
{
break;
}
$count++;
}
fclose($file);
}
?>
Look forward to hearing from you all, thanks!
-mike