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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

	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;
	}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.