@ 2013-02-11T16:21:20Z <?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 bool
*/
function simplexml_is_documentelement(SimpleXMLElement $element)
{
list($elementNode) = $element->xpath('.');
list($documentElement) = $element->xpath('/*');
return $elementNode == $element and $documentElement == $element;
}
$documentElement = $simple;
$attributeList = $simple->child->grandchild->attributes();
$attributeListEmpty = $simple->child->attributes();
$attribute = $simple->child->grandchild['a1'];
$suite = array(
'is_documentelement' => array('simplexml_is_documentelement', array(
array(true, $documentElement),
array(false, $documentElement->child),
array(false, $documentElement->single),
array(true, reset(($simple->xpath('/*')))),
array(true, reset(($simple->simple->xpath('/*')))),
array(false, $documentElement->child[0]),
array(false, $documentElement->child->grandchild),
array(false, $attribute),
array(false, $attributeList),
array(false, $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 git.master , git.master_jit , rfc.property-hooks Notice: Only variables should be passed by reference in /in/7UdCM on line 50
Notice: Only variables should be passed by reference in /in/7UdCM on line 51
Fatal error: Uncaught TypeError: reset(): Argument #1 ($array) must be of type array, null given in /in/7UdCM:51
Stack trace:
#0 /in/7UdCM(51): reset(NULL)
#1 {main}
thrown in /in/7UdCM on line 51
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
51.7 ms | 401 KiB | 8 Q