3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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_attribute(SimpleXMLElement $element) { return $element->attributes() !== null and !$element->children(); } $documentElement = $simple; $attributeList = $simple->child->grandchild->attributes(); $attributeListEmpty = $simple->child->attributes(); $attribute = $simple->child->grandchild['a1']; $suite = array( 'is_attribute' => array('simplexml_is_attribute', array( array(true, $attribute), array(true, $documentElement->child[0]['a3']), array(false, $attributeList), array(false, $attributeListEmpty), array(false, $documentElement), array(false, $documentElement->child), array(false, $documentElement->child[0]), )), ); 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 7.0.7 - 7.1.0
Running tests with LIBXML 2.9.4: . Fatal error: Uncaught TypeError: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given, called in /in/M8SsZ on line 109 and defined in /in/M8SsZ:31 Stack trace: #0 /in/M8SsZ(109): simplexml_is_attribute(NULL) #1 /in/M8SsZ(92): run_test(true, NULL, 'simplexml_is_at...', 'is_attribute #1') #2 /in/M8SsZ(63): run_testcase(Array, 'simplexml_is_at...', 'is_attribute') #3 /in/M8SsZ(56): run_test_suite(Array) #4 {main} thrown in /in/M8SsZ on line 31
Process exited with code 255.
Output for 7.0.0 - 7.0.6
Running tests with LIBXML 2.9.3: . Fatal error: Uncaught TypeError: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given, called in /in/M8SsZ on line 109 and defined in /in/M8SsZ:31 Stack trace: #0 /in/M8SsZ(109): simplexml_is_attribute(NULL) #1 /in/M8SsZ(92): run_test(true, NULL, 'simplexml_is_at...', 'is_attribute #1') #2 /in/M8SsZ(63): run_testcase(Array, 'simplexml_is_at...', 'is_attribute') #3 /in/M8SsZ(56): run_test_suite(Array) #4 {main} thrown in /in/M8SsZ on line 31
Process exited with code 255.
Output for hhvm-3.12.0
Running tests with LIBXML 2.9.3: . Fatal error: Uncaught TypeError: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given in /in/M8SsZ:34 Stack trace: #0 /in/M8SsZ(109): simplexml_is_attribute() #1 /in/M8SsZ(92): run_test() #2 /in/M8SsZ(63): run_testcase() #3 /in/M8SsZ(56): run_test_suite() #4 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Running tests with LIBXML 2.9.2: . Catchable fatal error: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given in /in/M8SsZ on line 34
Process exited with code 255.
Output for 5.5.36 - 5.5.38, 5.6.22 - 5.6.28
Running tests with LIBXML 2.9.4: . Catchable fatal error: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given in /in/M8SsZ on line 31
Process exited with code 255.
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.21
Running tests with LIBXML 2.9.3: . Catchable fatal error: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given in /in/M8SsZ on line 31
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Running tests with LIBXML 2.9.2: . Catchable fatal error: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given in /in/M8SsZ on line 31
Process exited with code 255.
Output for 5.3.25 - 5.3.29
Running tests with LIBXML 2.9.1: . Catchable fatal error: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given in /in/M8SsZ on line 31
Process exited with code 255.
Output for 5.3.15 - 5.3.24
Running tests with LIBXML 2.8.0: . Catchable fatal error: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given in /in/M8SsZ on line 31
Process exited with code 255.
Output for 5.2.0 - 5.3.14
Running tests with LIBXML 2.7.8: . Catchable fatal error: Argument 1 passed to simplexml_is_attribute() must be an instance of SimpleXMLElement, null given in /in/M8SsZ on line 31
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Running tests with LIBXML 2.7.8: . Fatal error: Argument 1 passed to simplexml_is_attribute() must not be null in /in/M8SsZ on line 31
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/M8SsZ on line 58
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/M8SsZ on line 31
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting ')' in /in/M8SsZ on line 31
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/M8SsZ on line 31
Process exited with code 255.