dimkasmir Posted February 27, 2009 Share Posted February 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 define tracknum as member variable class geocoin { private tracknum; function __construct($track) { $this->tracknum = $track; } function returnTrackNum() { return $this->tracknum; } Quote Link to comment Share on other sites More sharing options...
dimkasmir Posted February 27, 2009 Author Share Posted February 27, 2009 Now I get this errror: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/13/d196500339/htdocs/geocoins/geocoin.php on line 4 Quote Link to comment Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 class geocoin { private $tracknum; function __construct($track) { $this->tracknum = $track; } function returnTrackNum() { return $this->tracknum; } oops ..forgot the $ sign... Quote Link to comment Share on other sites More sharing options...
dimkasmir Posted February 27, 2009 Author Share Posted February 27, 2009 Nope, still getting the same error. Quote Link to comment Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 class geocoin { var $tracknum; function __construct($track) { $this->tracknum = $track; } function returnTrackNum() { return $this->tracknum; } try this.. Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2009 Share Posted February 27, 2009 That should be working fine, what version of php are you using? Quote Link to comment Share on other sites More sharing options...
dimkasmir Posted February 27, 2009 Author Share Posted February 27, 2009 I'm not getting an error anymore but this time it's echoing fail again. Quote Link to comment Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 i think u r using PHP4... try this.. class geocoin { var $tracknum; function geocoin($track) { $this->tracknum = $track; } function returnTrackNum() { return $this->tracknum; } Quote Link to comment Share on other sites More sharing options...
dimkasmir Posted February 27, 2009 Author Share Posted February 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 u want to read a URL? Quote Link to comment Share on other sites More sharing options...
dimkasmir Posted February 27, 2009 Author Share Posted February 27, 2009 yes Quote Link to comment Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 sorry ! i am not aware of a work around for this ! but that flag is specially defined to block such thing, so my assumption is it will be difficult to fo a workaround...but may be i am wrong. Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2009 Share Posted February 27, 2009 In your .htaccess.... php_flag allow_url_fopen on Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2009 Share Posted February 27, 2009 Actually, I think that will only work in versions lower than 4.3.4. It seems you need access to the ini file to enable that setting now. Quote Link to comment Share on other sites More sharing options...
dimkasmir Posted February 27, 2009 Author Share Posted February 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2009 Share Posted February 27, 2009 Is there any way to fix this? Wouldn't know without seeing the relevent code. Also, is it possible to read only a part of the file, not the whole thing? No. Quote Link to comment Share on other sites More sharing options...
dimkasmir Posted February 27, 2009 Author Share Posted February 27, 2009 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; } } Quote Link to comment 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.