3v4l.org

run code in 300+ PHP versions simultaneously
<?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, $simple->xpath('/*')[0]), array($documentElement, $simple->simple->xpath('/*')[0]), 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; }
Output for git.master, git.master_jit
Warning: Trying to access array offset on value of type null in /in/jX5tM on line 51 Running tests with LIBXML 2.9.4: .... Fatal error: Uncaught TypeError: simplexml_get_documentelement(): Argument #1 ($element) must be of type SimpleXMLElement, null given, called in /in/jX5tM on line 114 and defined in /in/jX5tM:31 Stack trace: #0 /in/jX5tM(114): simplexml_get_documentelement(NULL) #1 /in/jX5tM(97): run_test(Object(SimpleXMLElement), NULL, 'simplexml_get_d...', 'get_documentele...') #2 /in/jX5tM(68): run_testcase(Array, 'simplexml_get_d...', 'get_documentele...') #3 /in/jX5tM(61): run_test_suite(Array) #4 {main} thrown in /in/jX5tM on line 31
Process exited with code 255.
Output for rfc.property-hooks
Warning: Trying to access array offset on null in /in/jX5tM on line 51 Running tests with LIBXML 2.9.4: .... Fatal error: Uncaught TypeError: simplexml_get_documentelement(): Argument #1 ($element) must be of type SimpleXMLElement, null given, called in /in/jX5tM on line 114 and defined in /in/jX5tM:31 Stack trace: #0 /in/jX5tM(114): simplexml_get_documentelement(NULL) #1 /in/jX5tM(97): run_test(Object(SimpleXMLElement), NULL, 'simplexml_get_d...', 'get_documentele...') #2 /in/jX5tM(68): run_testcase(Array, 'simplexml_get_d...', 'get_documentele...') #3 /in/jX5tM(61): run_test_suite(Array) #4 {main} thrown in /in/jX5tM on line 31
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:
41.45 ms | 401 KiB | 8 Q