@ 2013-02-11T15:42:41Z <?php
/**
* SimpleXMLElement Introspection
*/
error_reporting(~0);
$xml = '<document>
<child>
give
<grandchild a1="v1" a2="v2">
me
</grandchild>
<grandchild>
more
</grandchild>
sugar.
</child>
<child>
</child>
<single/>
</document>
';
$simple = new SimpleXMLElement($xml);
/**
* @param SimpleXMLElement $element
* @return mixed
*/
function simplexml_get_documentelement(SimpleXMLElement $element)
{
foreach($element as $element) break;
list($documentElement) = $element->xpath('/*');
return $documentElement;
}
$documentElement = $simple;
$attributeList = $simple->child->grandchild->attributes();
$attributeListEmpty = $simple->child->attributes();
$attribute = $simple->child->grandchild['a1'];
$suite = array(
'get_documentelement' => array('simplexml_get_documentelement', array(
array($documentElement, $documentElement),
array($documentElement, $documentElement->child),
array($documentElement, $documentElement->single),
array($documentElement, reset(($simple->xpath('/*')))),
array($documentElement, reset(($simple->simple->xpath('/*')))),
array($documentElement, $documentElement->child[0]),
array($documentElement, $documentElement->child->grandchild),
array($documentElement, $attribute),
array($documentElement, $attributeList),
array(NULL, $attributeListEmpty),
)),
);
echo "Running tests with LIBXML ", LIBXML_DOTTED_VERSION, ":\n";
run_test_suite($suite);
function run_test_suite(array $testsuite)
{
foreach ($testsuite as $caselabel => $testcasedef) {
list($callback, $testcase) = $testcasedef;
$stats[] = run_testcase($testcase, $callback, $caselabel);
}
echo "\n";
$stat['tests'] = 0;
$stat['failures'] = 0;
foreach ($stats as $singled) {
$stat['tests'] += $singled['tests'];
$stat['failures'] += $singled['failures'];
echo $singled['messages'];
}
printf("Done %d tests with %d failures.", $stat['tests'], $stat['failures']);
}
function run_testcase(array $testcase, $callback, $label = null)
{
if ($label === null) $label = $callback;
$stats['tests'] = 0;
$stats['failures'] = 0;
$messages = '';
foreach ($testcase as $i => $test) {
list($expected, $subject, $testlabel) = $test + array(2 => "#$i");
$labeltest = $label . ' ' . $testlabel;
ob_start();
$result = run_test($expected, $subject, $callback, $labeltest);
$buffer = ob_get_clean();
echo $result ? '.' : 'F';
if ($buffer) {
$messages .= sprintf("### %s ###\n", $labeltest);
$messages .= $buffer;
}
$stats['tests']++;
if (!$result) $stats['failures']++;
}
return $stats + array('messages' => $messages);
}
function run_test($expected, $subject, $callback, $label)
{
$actual = call_user_func($callback, $subject);
if ($expected instanceof SimpleXMLElement and $actual instanceof SimpleXMLElement) {
$result = $actual == $expected;
} else {
$result = $actual === $expected;
}
if (!$result) {
$extra = '';
if ($subject instanceof SimpleXMLElement) {
$extra = sprintf(' with %s', rtrim($subject->asXML()));
}
printf("FAILED to test %s%s.\n", $label, $extra);
echo 'expected: ', var_dump($expected);
echo 'actual:', var_dump($actual);
}
return $result;
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Notice: Only variables should be passed by reference in /in/jivNq on line 50
Notice: Only variables should be passed by reference in /in/jivNq on line 51
Fatal error: Uncaught TypeError: reset(): Argument #1 ($array) must be of type array, null given in /in/jivNq:51
Stack trace:
#0 /in/jivNq(51): reset(NULL)
#1 {main}
thrown in /in/jivNq on line 51
Process exited with code 255 . Output for 7.0.0 - 7.0.5 , 7.0.7 - 7.0.20 , 7.1.0 - 7.1.7 , 7.1.20 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Notice: Only variables should be passed by reference in /in/jivNq on line 50
Notice: Only variables should be passed by reference in /in/jivNq on line 51
Running tests with LIBXML 2.9.4:
..........
Done 10 tests with 0 failures. Output for 7.1.10 Notice: Only variables should be passed by reference in /in/jivNq on line 50
Notice: Only variables should be passed by reference in /in/jivNq on line 51
Running tests with LIBXML 2.9.5:
..........
Done 10 tests with 0 failures. Output for 7.0.6 Notice: Only variables should be passed by reference in /in/jivNq on line 50
Notice: Only variables should be passed by reference in /in/jivNq on line 51
Running tests with LIBXML 2.9.3:
..........
Done 10 tests with 0 failures. Output for 5.5.36 - 5.5.38 , 5.6.0 - 5.6.20 , 5.6.22 - 5.6.26 Running tests with LIBXML 2.9.4:
..........
Done 10 tests with 0 failures. Output for 5.5.0 - 5.5.35 , 5.6.21 Running tests with LIBXML 2.9.3:
..........
Done 10 tests with 0 failures. Output for 5.4.0 - 5.4.45 Running tests with LIBXML 2.9.2:
..........
Done 10 tests with 0 failures. Output for 5.3.25 - 5.3.29 Running tests with LIBXML 2.9.1:
..........
Done 10 tests with 0 failures. Output for 5.3.15 - 5.3.24 Running tests with LIBXML 2.8.0:
..........
Done 10 tests with 0 failures. Output for 5.1.2 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.14 Running tests with LIBXML 2.7.8:
..........
Done 10 tests with 0 failures. Output for 5.1.0 - 5.1.1 Running tests with LIBXML 2.7.8:
.........F
### get_documentelement #9 ###
FAILED to test get_documentelement #9 with .
expected: NULL
actual:object(SimpleXMLElement)#8 (2) {
["child"]=>
array(2) {
[0]=>
string(51) "
give
sugar.
"
[1]=>
object(SimpleXMLElement)#20 (1) {
[0]=>
string(5) "
"
}
}
["single"]=>
object(SimpleXMLElement)#21 (0) {
}
}
Done 10 tests with 1 failures. Output for 5.0.0 - 5.0.5 Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/jivNq on line 63
Process exited with code 255 . Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/jivNq on line 31
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/jivNq on line 31
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error, expecting `')'' in /in/jivNq on line 31
Process exited with code 255 . preferences:dark mode live preview
247.13 ms | 401 KiB | 373 Q