ID:               44926
 User updated by:  francesco dot spegni at gmail dot com
 Reported By:      francesco dot spegni at gmail dot com
 Status:           Wont fix
 Bug Type:         DOM XML related
 Operating System: ubuntu
 PHP Version:      5.2.6
 New Comment:

well, let's say i'm realizing a PHP interpreter in ... PHP itself. of
course the interpreter will try to write PHP code fragments and will
evaluate it through the eval() function.

now, let's say that the interpreter has to execute program A and then
program B. let's say, for example, they are two parts of the same
program C. then, the environment of A has to be "passed" to B, so it can
access it. what i do, with the interpreter, is:

1. add before A's code, a set of instructions in order to "initialize"
A's environment

2. evaluate A code (PS let's suppose A makes use of some DOMDocument
object in itself)

3. when A code terminates, i do some elaboration with A's returned
result 

4. successively, i execute B code. in order to make B able to read A's
environment, i prepend to B code, some code in order to recreate the
environment left by A. this means that i will do something like:

$theCode = "\$var1 = ".var_export($var1).";\n";
$theCode = $theCode . "\$var2 = ".var_export($var2).";\n";
...
$theCode = $theCode . $codeOf_B;

5. the interpreter will evaluate $theCode hoping that $codeOf_B will
start with the same environment as left by the previous evaluation

unfortunately point 5 won't happen: the eval function will signal the
error because DOMDocument::__set_state() function does not exist. and
then: if DOMDocument::__set_state() should not exist, why the var_export
function export such a string?!? the definition of var_export tells that
var_export should return valid PHP code. am i wrong? otherwise, wouldn't
be better to throw an Exception when doing var_export of something that
does not admit a __set_state function for rebuilding it?!?

many thanks in advance for your reply

PS
is there any way to know in advance which classes have a __set_state
and which ones have not? is there another way to pass an environment to
the code run by eval()?!?


Previous Comments:
------------------------------------------------------------------------

[2008-05-06 12:06:55] [EMAIL PROTECTED]

What do you want to achieve with that anyway? You can't var_export a 
DOMDocument, not at least to something useful. You have to use
->saveXML 
and ->loadXML(), if you want to serialize a DOMDocument.




------------------------------------------------------------------------

[2008-05-06 10:15:12] francesco dot spegni at gmail dot com

Description:
------------
please, my php version is not actually 5.2.6, but PHP 5.2.4-2ubuntu5
with Suhosin-Patch 0.9.6.2. i'm sorry to have cheated, but i was not
able to install the last version without messing my system, and looking
for the changelogs i didn't find any reference to a problem like the one
i'm signaling. to me, it seems that the version i have is the last one
in the ubuntu's repositories.

when i execute the following code, var_export produce a
DOMDocument::__set_state call, but the eval function says that
DOMDocument::__set_state function does not exist.

Fatal error: Call to undefined method DOMDocument::__set_state() in
/home/spegni/Eclipse/workspace/automa_interpreter/test_bug.php(8) :
eval()'d code on line 1

i've searched through the documentation, finding nothing interesting
and to me it seems a buggy behavior. let me know if i'm wrong. many
thanks in advance.

Reproduce code:
---------------
<?php
$foo = new DOMDocument();
$strCode = "\$object = " . var_export($foo, TRUE) . "; return 1;";
print "execute: \n\n".$strCode."\n";
$resEval = eval($strCode);
print "eval returned: " . $resEval . "\n";
?>


Expected result:
----------------
i expect the eval code to be executed without error and return result
"1"

Actual result:
--------------
Fatal error: Call to undefined method DOMDocument::__set_state() in
/home/spegni/Eclipse/workspace/automa_interpreter/test_bug.php(8) :
eval()'d code on line 1



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44926&edit=1

Reply via email to