Jump to content


Photo

A problem with PHP 4.3.11 and PHP 5.1.2 object reference (SOLVED)


  • Please log in to reply
6 replies to this topic

#1 mlavwilson

mlavwilson
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 08 October 2006 - 12:34 PM

I have the following code that works great on my 5.1.2 local instance, then when I deploy it to my goDaddy server which is running 4.3.11, the $league varable does not contain any coaches that the FranchiseHandler created.  I know the sax parse is working (see: http://www.ffauthori...ction/parse.php), because the echo is displaying the ids.  However the $league varable seams to have messed up scope on hte 4.3.11 instance, aAny ideas?
<?php
if (!defined("XOOPS_ROOT_PATH"))
{
	die("XOOPS root path not defined");
}

require (XOOPS_ROOT_PATH."/class/ff/League.php");
require (XOOPS_ROOT_PATH."/class/snoopy.php");
require (XOOPS_ROOT_PATH."/class/xml/saxparser.php");
require (XOOPS_ROOT_PATH."/class/xml/xmltaghandler.php");

class MflParser
{
	var $version = "1.0.0";
	var $xml;
	var $league;

	function doParse($leagueId)
	{
		$this->league = new League($leagueId);
		$file = "http://football.myfantasyleague.com/2006/export?L=".$leagueId."&TYPE=league";
		$snoopy = new Snoopy();
		if (!$snoopy->fetch($file) || !$snoopy->results)
		{
			$this->_setErrors('Could not open file: '.$file);
			if (!empty ($snoopy->error))
				$this->_setErrors("Snoopy status=".htmlspecialchars($snoopy->error));
			if ($snoopy->timed_out)
				$this->_setErrors("Timed out");
		}
		$this->xml = $snoopy->results;

		$leagueParser = new Mfl2Parser($snoopy->results, $this->league);
		if (!$leagueParser->parse())
		{
			$this->_setErrors($this->_parser->getErrors(false));
			unset ($leagueParser);
			return false;
		}
	}
}

class Mfl2Parser extends SaxParser
{
	var $league;
	
	function Mfl2Parser($input, &$league)
	{
		$this->SaxParser($input);
		$this->useUtfEncoding();
		$this->addTagHandler(new FranchiseHandler());
		$this->league = $league;
	}
}

class FranchiseHandler extends XmlTagHandler
{
	function FranchiseHandler()
	{
	}

	function getName()
	{
		return "franchise";
	}

	function handleBeginElement($parser, $attributes)
	{
		$coach = new Coach($attributes["id"], $attributes["name"]);
		$parser->league->coaches[$coach->id] = $coach;
		echo $attributes["id"] . "-" . $attributes["name"];
	}
}
?>

<?php

class League
{
	var $id;
  var $coaches = array();
  
  function League($id)
	{
		$this->id = $id;
	}
}

class Coach
{
  var $id;
  var $name;
  var $players = array();
  
  function Coach($id, $name)
	{
		$this->id = $id;
		$this->name = $name;
	}
}

class Player
{
  var $id;
  var $internalId;
}
?>


#2 mlavwilson

mlavwilson
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 08 October 2006 - 11:36 PM

*bump*

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 09 October 2006 - 01:15 AM

this may be completely off the map - but does your godaddy server allow teh short php tags '<?'

as that is the opening tag of an xml declaration - so there may be some conflict

follow me on twitter @PHPsycho

#4 mlavwilson

mlavwilson
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 October 2006 - 11:57 AM

*bump*

It seams that the scope of the $league varable gets lost when the parser returns.  This is driving me crazy!

#5 mlavwilson

mlavwilson
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 October 2006 - 02:56 PM

*bump*

#6 mlavwilson

mlavwilson
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 October 2006 - 06:04 PM

*bump*

#7 mlavwilson

mlavwilson
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 10 October 2006 - 03:08 PM

My problem was this line:
$this->league = $league;
It needed to be:
$this->league = & $league;





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users