3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = ' <content> <hello attribute="123"></hello> </content> '; class Parser { private $xml; public function __construct(SimpleXMLElement $xml) { $this->xml = $xml; } public function asString(): string { return $this->getValue(); } public function asInt(): int { return $this->getValue(); } public function asCastedInt(): int { return $this->asString(); } public function directConversion() { return (int)$this->getValue(); } private function getValue() { return $this->xml->hello['attribute']; } } $object = new Parser(new SimpleXMLElement($xml)); var_dump($object->asString()); var_dump($object->asCastedInt()); var_dump($object->directConversion()); var_dump($object->asInt());
Output for git.master, git.master_jit, rfc.property-hooks
string(3) "123" int(123) int(123) Fatal error: Uncaught TypeError: Parser::asInt(): Return value must be of type int, SimpleXMLElement returned in /in/JnFCh:22 Stack trace: #0 /in/JnFCh(44): Parser->asInt() #1 {main} thrown in /in/JnFCh on line 22
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:
63.49 ms | 401 KiB | 8 Q