Reply to PHP5, $_SESSION, DOM XML objects not returning value

Your name:

Reply:


Posted by "Daevid Vincent" on 10/01/05 01:01

I'm trying to store an array of DOM XML objects
(http://www.php.net/manual/en/ref.dom.php) in a PHP5.0.3 $_SESSION array,
but when I load the session back (and yes, I've declared my class before the
session_start()), I get these errors:

Warning: XMLRule::getValue() [function.getValue]: Invalid State Error
in /lockdown/includes/classes/rule_xml.class.php on line 74

Or

Warning: XMLRule::getValue() [function.getValue]: Invalid State Error
in /lockdown/includes/classes/rule_xml.class.php on line 81

And all the VALUES are empty, however *my* XMLRule class array seems right
otherwise. It's like PHP didn't serialize all of it's own DOM XML objects
(which are built in objects!!!)

Here are the pertinent parts of the classes and other code snippets.

############################################################################
#####
class XMLRule
{
// for example 'is_username' XML tag would set $name = 'Username'
protected $name = null;

// The reference pointer to the DOMNode, this is a wealth of
information in itself.
// look at the DOMNode class @
http://www.php.net/manual/en/ref.dom.php
protected $DOMNode = null;

protected function __construct($DOMNode, $name, $id = null)
{
$this->DOMNode = $DOMNode;
$this->name = $name;
$this->id = $id;
} //__construct()


function getValue()
{
//check for multiple values, such as a list of names perhaps
[#74] if ($this->DOMNode->childNodes->length > 1)
{
foreach ($this->DOMNode->childNodes as $tmpNode)
$tmpArray[] = $tmpNode->nodeValue;
return $tmpArray;
}
else
[#81] return $this->DOMNode->nodeValue;
}
}

class is_username extends XMLRule
{
function __construct($DOMNode, $id = null) {
parent::__construct($DOMNode, 'Username', $id); }
}

class is_day extends XMLRule
{
function __construct($DOMNode, $id = null) {
parent::__construct($DOMNode, 'Day', $id); }
}

....etc...

############################################################################
#####

// IMPORTANT: You *MUST* declare the class *BEFORE* you call
session_start().
// If you run session_start() before the definition of the class,
// the session variables of the objects will be corrupted.
// http://www.zend.com/phorum/read.php?num=3&id=36854&thread=36847

require_once('classes/rule_xml.class.php');

if (!isset($_SESSION['ruleArray']))
{
$XMLDOC = new DOMDocument();
$XMLDOC->loadXML($xmlstring);

$ruleArray = array();
$i = 1;
$or = 1;
foreach($XMLDOC->firstChild->childNodes as $myNode)
{
if ($myNode->nodeName == 'and_conditions')
{
foreach($myNode->childNodes as $cNode)
{
$key = (string)($cNode->nodeName);
//make a new instance of the node name'd
class
$ruleArray[$or][$i] = new $key($cNode, $i);
$i++;
}

$or++; //begin new OR block
} //if and_conditions
} //foreach $myNode

$_SESSION['ruleArray'] = serialize($ruleArray);
}
else $ruleArray = unserialize($_SESSION['ruleArray']);

I've tried this with the un/serialize and without. PHP5 is supposed to
handle that for me, but just in case, I tried it anyways.

If I don't use the $SESSION, then things work fine and I have my values.

I also tried to do this:

$_SESSION['ruleArray'] = $ruleArray;
$ruleArray = $_SESSION['ruleArray'];

And surprisingly that works (although it doesn't solve my problem).

############################################################################
#####
Upon loading this back, this is what the array looks like in either case
(working or not)

Array
(
[1] => Array
(
[1] => is_username Object
(
[name:protected] => Username
[DOMNode:protected] => DOMElement Object
(
)
[id:protected] => 1
)

[2] => is_day Object
(
[name:protected] => Day
[DOMNode:protected] => DOMElement Object
(
)
[id:protected] => 2
)

...etc...

############################################################################
#####

PHP Version 5.0.3

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
with Zend Extension Manager v1.0.6, Copyright (c) 2003-2004, by Zend
Technologies
with Zend Optimizer v2.5.7, Copyright (c) 1998-2004, by Zend
Technologies

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация