Jump to content

[SOLVED] Variable Not Assigning in Class Constructor


dimkasmir

Recommended Posts

This is the code for my class constructor as well as one function:

 

class geocoin
{
function __construct($track)
{
	$this->tracknum = $track;
}

function returnTrackNum()
{
	return $this->tracknum;
}

 

However, the variable $tracknum does not set because when I run this code:

 

$coins = new geocoin("test");
$num = $coins->returnTrackNum();
if (!isset($num))
{
echo "fail";
}

 

I can see that it is empty. Can someone tell me what I am doing wrong?

I've solved this problem: my host was defaulting to PHP 4. All I had to do was make a .htaccess file. Now I have a new problem. Later in the script I use the file_get_contents() function. However, the host has URL file-access disabled. Is there anyway to enable it without having access to the php.ini file?

I was able to change this by making an ini file in the directory. Now after I launch the script a few times and everything displays correctly, its stops reading the page for some time. Then if I launch it again a little later it works but after a few times stops working again. Is there any way to fix this? Also, is it possible to read only a part of the file, not the whole thing?

	function getPage()
{
	$this->page = file_get_contents("http://www.geocaching.com/track/details.aspx?tracker=".$this->tracknum);
	return $this->page;
}

function getName()
{
	preg_match('#<span id="ctl00_ContentBody_lbHeading">(.+)</span>#', $this->getPage(), $match);
	if(isset($match[1]) && $match[1] != '')
	{
		$this->name = $match;
		return $this->name[1];
	}
	else
	{
		return FALSE;
	}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.