php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44926 DOMDocument::__set_state function does not exists
Submitted: 2008-05-06 10:15 UTC Modified: 2008-05-06 13:47 UTC
From: francesco dot spegni at gmail dot com Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 5.2.6 OS: ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: francesco dot spegni at gmail dot com
New email:
PHP Version: OS:

 

 [2008-05-06 10:15 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-06 12:06 UTC] chregu@php.net
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 13:47 UTC] francesco dot spegni at gmail dot com
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()?!?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 12:01:27 2024 UTC